Class: JrubyCoercion::RubyToJava::Registry

Inherits:
JrubyCoercion::Registry show all
Defined in:
lib/jruby_coercion/ruby_to_java/registry.rb

Constant Summary collapse

DEFAULT_CONVERTER =
lambda { |val| val.jruby_default_to_java }
DEFAULT_TYPE_MAP =

Setup a default type mapping to correctly respond to #coerce_to? calls and register the default mapping

{
  Fixnum => java.lang.Long,
  TrueClass => java.lang.Boolean,
  FalseClass => java.lang.Boolean,
  Float => java.lang.Double,
  BigDecimal => java.math.BigDecimal,
  String => java.lang.String
}

Constants inherited from JrubyCoercion::Registry

JrubyCoercion::Registry::DEFAULT_KEY

Class Method Summary collapse

Methods inherited from JrubyCoercion::Registry

alternative_class, converter_registry, register_converter, registry_converts_class?, registry_converts_class_and_to?

Class Method Details

.new_registry_entry_for_type(from_type) ⇒ Object

Override for new_registry_entry_for_type in RubyToJava that calls jruby default to_java when nil is the to_type



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/jruby_coercion/ruby_to_java/registry.rb', line 26

def self.new_registry_entry_for_type(from_type)
  new_type_registry = Java::JavaUtilConcurrent::ConcurrentHashMap.new
  new_type_registry[::JrubyCoercion::Registry::DEFAULT_KEY] = DEFAULT_CONVERTER
  
  if (mapped_to = DEFAULT_TYPE_MAP[from_type])
    new_type_registry[mapped_to] = DEFAULT_CONVERTER
  end

  # Class should include Coercable
  from_type.__send__(:include, ::JrubyCoercion::Coercable)

  return new_type_registry
end