Class: Mapper

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMapper

Returns a new instance of Mapper.



100
101
102
103
# File 'lib/hash_to_model_mapper.rb', line 100

def initialize
  @transformers = {}
  @attributes = {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *path, **args, &block) ⇒ Object



107
108
109
110
# File 'lib/hash_to_model_mapper.rb', line 107

def method_missing(name, *path, **args, &block)
  @transformers[name] = args[:transform]
  @attributes[name] = path.presence || block
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



105
106
107
# File 'lib/hash_to_model_mapper.rb', line 105

def attributes
  @attributes
end

#transformersObject (readonly)

Returns the value of attribute transformers.



105
106
107
# File 'lib/hash_to_model_mapper.rb', line 105

def transformers
  @transformers
end