Class: Mapping::Model
- Inherits:
-
Object
- Object
- Mapping::Model
- Defined in:
- lib/mapping/model.rb
Constant Summary collapse
- PREFIX =
'map_'.freeze
Class Method Summary collapse
- .map(klass, &block) ⇒ Object
-
.method_for_mapping(klass) ⇒ Object
This function generates mapping names like ‘map_Array` and `map_Hash` which while a bit non-standard are perfectly fine for our purposes and this never really needs to leak.
Instance Method Summary collapse
Class Method Details
.map(klass, &block) ⇒ Object
34 35 36 37 |
# File 'lib/mapping/model.rb', line 34 def self.map(klass, &block) method_name = self.method_for_mapping(klass) define_method(method_name, &block) end |
.method_for_mapping(klass) ⇒ Object
This function generates mapping names like ‘map_Array` and `map_Hash` which while a bit non-standard are perfectly fine for our purposes and this never really needs to leak.
26 27 28 |
# File 'lib/mapping/model.rb', line 26 def self.method_for_mapping(klass) PREFIX + klass.name.gsub(/::/, '_') end |
Instance Method Details
#map(root, *args) ⇒ Object
59 60 61 62 63 |
# File 'lib/mapping/model.rb', line 59 def map(root, *args) method_name = self.method_for_mapping(root) self.send(method_name, root, *args) end |
#method_for_mapping(object) ⇒ Object
30 31 32 |
# File 'lib/mapping/model.rb', line 30 def method_for_mapping(object) self.class.method_for_mapping(object.class) end |