Class: Fiona7::AttributeTypeMapper::CustomAttributeTypeMapper

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

Instance Method Summary collapse

Constructor Details

#initialize(obj_class, source) ⇒ CustomAttributeTypeMapper

Returns a new instance of CustomAttributeTypeMapper.



31
32
33
34
# File 'lib/fiona7/attribute_type_mapper.rb', line 31

def initialize(obj_class, source)
  self.obj_class = obj_class
  self.source = source
end

Instance Method Details

#call(attribute, virtual_type) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/fiona7/attribute_type_mapper.rb', line 36

def call(attribute, virtual_type)
  return nil if source.kind_of?(Hash) && source.empty?

  if source.kind_of? Hash
    (source[self.obj_class] || {})[attribute] || source[attribute]
  elsif source.respond_to? :call
    source.call(self.obj_class, attribute)
  else
    nil
  end
end