jruby-coercion 0.0.1-java → 0.0.2-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.
- data/lib/jruby-coercion.rb +20 -1
- data/lib/jruby-coercion/numeric.rb +12 -12
- data/lib/jruby-coercion/version.rb +1 -1
- metadata +2 -2
data/lib/jruby-coercion.rb
CHANGED
@@ -5,13 +5,29 @@ require "java"
|
|
5
5
|
module Jruby
|
6
6
|
module Coercion
|
7
7
|
|
8
|
+
def self.native_type?(java_type)
|
9
|
+
java_type.class == Java::JavaClass
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.ruby_type?(java_type)
|
13
|
+
java_type.class == Class
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.alternative_class(java_type)
|
17
|
+
if native_type?(java_type)
|
18
|
+
return java_type.ruby_class
|
19
|
+
else
|
20
|
+
return java_type.java_class
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
8
24
|
module Coercable
|
9
25
|
def to_java(java_type = nil)
|
10
26
|
return super if java_type.nil?
|
11
27
|
converter = ::Jruby::Coercion::Registry.registry_converts_class_and_to?(self.class, java_type)
|
12
28
|
|
13
29
|
if converter
|
14
|
-
return converter.call(self
|
30
|
+
return converter.call(self)
|
15
31
|
else
|
16
32
|
super
|
17
33
|
end
|
@@ -32,6 +48,9 @@ module Jruby
|
|
32
48
|
::Java::JavaUtilConcurrent::ConcurrentHashMap.new)
|
33
49
|
|
34
50
|
ruby_type_converter[java_type] = callable
|
51
|
+
# Register alternative type java_class/ruby_class
|
52
|
+
ruby_type_converter[::Jruby::Coercion.alternative_class(java_type)] = callable
|
53
|
+
|
35
54
|
@converter_registry[ruby_type] = ruby_type_converter
|
36
55
|
end
|
37
56
|
end
|
@@ -5,27 +5,27 @@ class Numeric
|
|
5
5
|
end
|
6
6
|
|
7
7
|
# java.math.BigDecimal
|
8
|
-
::Jruby::Coercion::Registry.register_converter(Numeric, java.math.BigDecimal) do |numeric
|
9
|
-
|
8
|
+
::Jruby::Coercion::Registry.register_converter(Numeric, java.math.BigDecimal) do |numeric|
|
9
|
+
java.math.BigDecimal.new(numeric)
|
10
10
|
end
|
11
11
|
|
12
|
-
::Jruby::Coercion::Registry.register_converter(Integer, java.math.BigDecimal) do |integer
|
13
|
-
|
12
|
+
::Jruby::Coercion::Registry.register_converter(Integer, java.math.BigDecimal) do |integer|
|
13
|
+
java.math.BigDecimal.new(integer)
|
14
14
|
end
|
15
15
|
|
16
|
-
::Jruby::Coercion::Registry.register_converter(Fixnum, java.math.BigDecimal) do |fixnum
|
17
|
-
|
16
|
+
::Jruby::Coercion::Registry.register_converter(Fixnum, java.math.BigDecimal) do |fixnum|
|
17
|
+
java.math.BigDecimal.new(fixnum)
|
18
18
|
end
|
19
19
|
|
20
20
|
# java.math.BigInteger
|
21
|
-
::Jruby::Coercion::Registry.register_converter(Numeric, java.math.BigInteger) do |numeric
|
22
|
-
|
21
|
+
::Jruby::Coercion::Registry.register_converter(Numeric, java.math.BigInteger) do |numeric|
|
22
|
+
java.math.BigInteger.new("#{numeric}")
|
23
23
|
end
|
24
24
|
|
25
|
-
::Jruby::Coercion::Registry.register_converter(Integer, java.math.BigInteger) do |integer
|
26
|
-
|
25
|
+
::Jruby::Coercion::Registry.register_converter(Integer, java.math.BigInteger) do |integer|
|
26
|
+
java.math.BigInteger.new("#{integer}")
|
27
27
|
end
|
28
28
|
|
29
|
-
::Jruby::Coercion::Registry.register_converter(Fixnum, java.math.BigInteger) do |fixnum
|
30
|
-
|
29
|
+
::Jruby::Coercion::Registry.register_converter(Fixnum, java.math.BigInteger) do |fixnum|
|
30
|
+
java.math.BigInteger.new("#{fixnum}")
|
31
31
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jruby-coercion
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: java
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-12-
|
12
|
+
date: 2012-12-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|