Class: JavaPackage

Inherits:
Object
  • Object
show all
Defined in:
lib/rjbextension.rb

Constant Summary

@@cache =
{}

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (JavaPackage) initialize(pack_name, parent_pack = nil)



78
79
80
81
82
# File 'lib/rjbextension.rb', line 78

def initialize(pack_name, parent_pack = nil)
  @pack_name = pack_name
  @parent_pack = parent_pack
  @cache = {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

- (Object) method_missing(m, *args)



84
85
86
87
# File 'lib/rjbextension.rb', line 84

def method_missing(m, *args)
  # return if possible old module/class
  @cache[m] ||= create_package_or_class(m)
end

Class Method Details

+ (Object) new(pack_name, parent_pack = nil)



111
112
113
# File 'lib/rjbextension.rb', line 111

def self.new(pack_name, parent_pack = nil)
  @@cache[pack_name] ||= super
end

Instance Method Details

- (Boolean) class?(a)



105
106
107
108
# File 'lib/rjbextension.rb', line 105

def class?(a)
  first_letter = a[0,1]
  first_letter >= 'A' && first_letter <= 'Z'
end

- (Object) create_package_or_class(m)



88
89
90
91
92
93
94
95
# File 'lib/rjbextension.rb', line 88

def create_package_or_class(m)
  method = m.to_s
  if class?(method)
    Rjb::import("#{self}.#{method}")
  else
    JavaPackage.new(method, self)
  end
end

- (Object) to_s



97
98
99
100
101
102
103
# File 'lib/rjbextension.rb', line 97

def to_s
  if @parent_pack
    "#{@parent_pack.to_s}.#@pack_name"
  else
    "#@pack_name"
  end
end