jtor-stdlib 0.1.4-java → 0.1.5-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 788765015218496bf8ce81d2ed3838276ac4d3ae
4
- data.tar.gz: 9fdc417d377720e73b8e422b738b55a8ae7aa8ee
3
+ metadata.gz: 71f904b093af11de537085c6b58792914df1adcc
4
+ data.tar.gz: 1d0c3b4522f450b4bbd91d5e3e4119e3e9be7af2
5
5
  SHA512:
6
- metadata.gz: 5fb439909e96c479f34295bd0cd9aa8809ed0ed668387ac7359c31016297ddc4887a3ba132b151300ecd33ed25fae9abdd0a29a12cf3cd001665e12fff086281
7
- data.tar.gz: 3fd35e1e3689304d0bb4c6f371a3541c81da6f34a4559ae6e2c05398d635e3896e0ce53d7de1da341fd55a11b8757224beac7844b5dbea2a76d8524185b7f09a
6
+ metadata.gz: 8baf987a374bc4600e2ef34fecd9e3b2f2f3be8f58659ef56b4e4aff3b728336d7882842c9836f87ca9a3856df74cd30aafa4d1d1743eefc333431f31af60256
7
+ data.tar.gz: f6a4436cd522220c6a6108bd6186d271bd9379a2b9aea06887d50f9c9c74e57b44342cac94aeaf0527b47cb0fa7b7075e5f9c1be460ae1b2de935b42e9ea38a3
@@ -5,6 +5,23 @@ module Jtor
5
5
  base.extend(ClassMethods)
6
6
  end
7
7
 
8
+ def initialize(*args)
9
+ method, constructor_call = self.class.lookup(:initialize, *args)
10
+ # I really tried to avoid using eval fellows, but JRuby is very fixed
11
+ # on `super` being called here first than anything, and it wouldn't
12
+ # accept a `proc` calling `initialize` on `sup`, so this will have
13
+ # to do for now.
14
+ if method
15
+ eval(constructor_call)
16
+ instance_exec(*args, &method)
17
+ else
18
+ super
19
+ end
20
+ self.class._initializers.each do |initializer|
21
+ instance_exec(*args, &initializer)
22
+ end
23
+ end
24
+
8
25
  def sup
9
26
  @_sup ||= SuperObject.new(self)
10
27
  end
@@ -22,6 +39,15 @@ module Jtor
22
39
  @_constructor_calls ||= {}
23
40
  end
24
41
 
42
+ def _initializers
43
+ @initializers ||= []
44
+ end
45
+
46
+ # For field initializers
47
+ def add_java_initializer(&block)
48
+ _initializers << block
49
+ end
50
+
25
51
  # Method overloading is not a ruby thing, so we implement a pseudo-lookup
26
52
  # mechanism for method based on the type/count of their args
27
53
  def add_java_method(name, param_types, &block)
@@ -44,18 +70,7 @@ module Jtor
44
70
 
45
71
  def add_java_constructor(param_types, constructor_call = nil, &block)
46
72
  add_method_to_lookup(_lookup_table, :initialize, param_types, &block)
47
- previously_defined = _constructor_calls.any?
48
73
  _constructor_calls[param_types] = constructor_call
49
- return if previously_defined
50
- define_method(:initialize) do |*args|
51
- method, constructor_call = self.class.lookup(:initialize, *args)
52
- # I really tried to avoid using eval fellows, but JRuby is very fixed
53
- # on `super` being called here first than anything, and it wouldn't
54
- # accept a `proc` calling `initialize` on `sup`, so this will have
55
- # to do for now.
56
- eval(constructor_call) #if constructor_call
57
- instance_exec(*args, &method)
58
- end
59
74
  end
60
75
 
61
76
  def lookup(name, *args)
@@ -5,7 +5,10 @@ module Jtor
5
5
  path = File.join(packages[0..-2], "#{packages.last}.rb")
6
6
  paths = Dir[path]
7
7
  if paths.any?
8
- paths.each { |p| require File.expand_path(p) }
8
+ # Our loading model exposes ourselves to loading child classes when
9
+ # loading their parents, so we rescue those errors and ignore them
10
+ # (when the child gets loaded everything will be fine).
11
+ paths.each { |p| require File.expand_path(p) rescue (NameError; nil) }
9
12
  else
10
13
  java_import import_string
11
14
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jtor-stdlib
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: java
6
6
  authors:
7
7
  - Alejandro Rodríguez