jtor-stdlib 0.1.0-java → 0.1.1-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: a0fdfc6074c7499532f2e3dd014930bba384aede
4
- data.tar.gz: fdf32a96588e40df135d24c36155d7c673c872f2
3
+ metadata.gz: 30f6a9eaeea71b4b9ed16ebf62ea7c995ed5b6f0
4
+ data.tar.gz: 510159c2e64ef1cbc76635a7fba3c204bc143361
5
5
  SHA512:
6
- metadata.gz: 894a61cbb2d23e7b24d7aa98323fdeee47fe09526951b2fdaa850855bc7f0aa599958599bc6b8cb2791dc45557c9d4a2c6134f66e1ac36256edff093d9ef40d4
7
- data.tar.gz: f1e5f839f16d855fbcf19d59aae44305a082247e1f9b047e9950a84d269da78f1bd080b472ffd57d6ccf9fa72be3e04b7c9e85d998c6f704577f3087912241ba
6
+ metadata.gz: 32fc80c2e1a9cd631845d8104e33d15b8360b60e36cee35ffca6f6b687116dc26f5736d242bf0120e577199465cd31361279de43ec24c2e35234634fdb970292
7
+ data.tar.gz: d187b0b8837f0e94729d9f2c61fd4495c99c65a504d442c283a4b66b4de9c331e58410dcd60de054ac2e62bc7683ea0f12e75a667612c2d9b6cd456b08f3e329
@@ -1,44 +1,42 @@
1
1
  module Jtor
2
2
  module StdLib
3
- class Base
3
+ module Base
4
4
  @@_lookup = {}
5
5
 
6
- class << self
7
- # Method overloading is not a ruby thing, so we implement a pseudo-lookup
8
- # mechanism for method based on the type/count of their args
9
- def add_java_method(name, param_types, &block)
10
- add_method_to_lookup(name, param_types, &block)
11
- unless method_defined?(name)
12
- define_method(name) { |*args| self.class.lookup(name, *args) }
13
- end
6
+ # Method overloading is not a ruby thing, so we implement a pseudo-lookup
7
+ # mechanism for method based on the type/count of their args
8
+ def add_java_method(name, param_types, &block)
9
+ add_method_to_lookup(name, param_types, &block)
10
+ unless method_defined?(name)
11
+ define_method(name) { |*args| self.class.lookup(name, *args) }
14
12
  end
13
+ end
15
14
 
16
- def lookup(name, *args)
17
- if @@_lookup[name]
18
- @@_lookup[name].each do |param_types, method|
19
- # NOTE: This is an oversimplification of the way Java determines
20
- # which method to invoke. I may work further into this later (see
21
- # http://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.12)
22
- next unless params_match(param_types, args)
23
- return method.call(*args)
24
- end
15
+ def lookup(name, *args)
16
+ if @@_lookup[name]
17
+ @@_lookup[name].each do |param_types, method|
18
+ # NOTE: This is an oversimplification of the way Java determines
19
+ # which method to invoke. I may work further into this later (see
20
+ # http://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.12)
21
+ next unless params_match(param_types, args)
22
+ return method.call(*args)
25
23
  end
26
- method_missing(name, *args)
27
24
  end
25
+ method_missing(name, *args)
26
+ end
28
27
 
29
- def params_match(types, values)
30
- # TODO: Handle var args (...)
31
- types.each_with_index do |type, index|
32
- value = values[index]
33
- return false unless value.is_a?(type) || value.to_java.is_a?(type)
34
- end
35
- true
28
+ def params_match(types, values)
29
+ # TODO: Handle var args (...)
30
+ types.each_with_index do |type, index|
31
+ value = values[index]
32
+ return false unless value.is_a?(type) || value.to_java.is_a?(type)
36
33
  end
34
+ true
35
+ end
37
36
 
38
- def add_method_to_lookup(name, param_types, &block)
39
- @@_lookup[name] ||= {}
40
- @@_lookup[name][param_types] = block
41
- end
37
+ def add_method_to_lookup(name, param_types, &block)
38
+ @@_lookup[name] ||= {}
39
+ @@_lookup[name][param_types] = block
42
40
  end
43
41
  end
44
42
  end
@@ -1,6 +1,13 @@
1
- def jtor_import(import_string)
2
- require import_string.split('.').join('/')
3
- rescue LoadError
4
- # :O `eval` 3spooky5me
5
- java_import eval(import_string)
1
+ module Jtor
2
+ module Imports
3
+ def jtor_import(import_string)
4
+ packages = import_string.split('.')
5
+ path = File.join(packages[0..-2], "#{packages.last}.rb")
6
+ Dir[path].each { |p| require File.expand_path(p) }
7
+ rescue LoadError
8
+ java_import import_string
9
+ end
10
+ end
6
11
  end
12
+
13
+ include Jtor::Imports
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.0
4
+ version: 0.1.1
5
5
  platform: java
6
6
  authors:
7
7
  - Alejandro Rodríguez