Module: Yaoc::MappingBase::ClassMethods
- Defined in:
- lib/yaoc/mapping_base.rb
Instance Method Summary collapse
-
#class_private_module(name = :Mapping) ⇒ Object
inspired by Avdi Grimm, rubytapas.com 028-macros-and-modules.
- #converter_methods ⇒ Object
- #map(to: nil, from: to, converter: nil, lazy_loading: false) ⇒ Object
- #mapping_strategy ⇒ Object
- #mapping_strategy=(new_strat) ⇒ Object
Instance Method Details
#class_private_module(name = :Mapping) ⇒ Object
inspired by Avdi Grimm, rubytapas.com 028-macros-and-modules
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/yaoc/mapping_base.rb', line 60 def class_private_module(name=:Mapping) if const_defined?(name, false) const_get(name) else new_mod = Module.new do def self.to_s "Mapping (#{instance_methods(false).join(', ')})" end def self.inspect to_s end end const_set(name, new_mod) end end |
#converter_methods ⇒ Object
55 56 57 |
# File 'lib/yaoc/mapping_base.rb', line 55 def converter_methods class_private_module(:Mapping).instance_methods(false).sort end |
#map(to: nil, from: to, converter: nil, lazy_loading: false) ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'lib/yaoc/mapping_base.rb', line 46 def map(to: nil, from: to, converter: nil, lazy_loading: false) class_private_module(:Mapping).tap do |mod| method_implementation = TransformationCommand.create(to: to, from: from, deferred: lazy_loading, conversion_proc: converter) mod.send :define_method, "map_#{"%04d" %[converter_methods.count]}_#{from}_to_#{to}".to_sym, method_implementation include mod end end |
#mapping_strategy ⇒ Object
42 43 44 |
# File 'lib/yaoc/mapping_base.rb', line 42 def mapping_strategy @mapping_strategy end |
#mapping_strategy=(new_strat) ⇒ Object
38 39 40 |
# File 'lib/yaoc/mapping_base.rb', line 38 def mapping_strategy=(new_strat) @mapping_strategy = new_strat end |