Class: Mapper
- Inherits:
-
Object
- Object
- Mapper
- Defined in:
- lib/hash_to_model_mapper.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#transformers ⇒ Object
readonly
Returns the value of attribute transformers.
Instance Method Summary collapse
-
#initialize ⇒ Mapper
constructor
A new instance of Mapper.
- #method_missing(name, *path, **args, &block) ⇒ Object
Constructor Details
#initialize ⇒ Mapper
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
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
105 106 107 |
# File 'lib/hash_to_model_mapper.rb', line 105 def attributes @attributes end |
#transformers ⇒ Object (readonly)
Returns the value of attribute transformers.
105 106 107 |
# File 'lib/hash_to_model_mapper.rb', line 105 def transformers @transformers end |