Class: LittleMapper::MappingFactory
- Inherits:
-
Object
- Object
- LittleMapper::MappingFactory
- Defined in:
- lib/little_mapper/mapping_factory.rb
Instance Method Summary collapse
-
#initialize(strategy = :activerecord) ⇒ MappingFactory
constructor
A new instance of MappingFactory.
- #map(mapper, field, opts = {}) ⇒ Object
- #one_to_many ⇒ Object
- #one_to_one ⇒ Object
- #strategy ⇒ Object
- #strategy_module ⇒ Object
Constructor Details
#initialize(strategy = :activerecord) ⇒ MappingFactory
Returns a new instance of MappingFactory.
4 5 6 |
# File 'lib/little_mapper/mapping_factory.rb', line 4 def initialize(strategy = :activerecord) @_strategy = strategy end |
Instance Method Details
#map(mapper, field, opts = {}) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/little_mapper/mapping_factory.rb', line 12 def map(mapper, field, opts = {}) if opts[:as] && opts[:as].is_a?(Array) as = opts.delete(:as) one_to_many.new(mapper, field, as[0], opts) else one_to_one.new(mapper, field, opts) end end |
#one_to_many ⇒ Object
32 33 34 |
# File 'lib/little_mapper/mapping_factory.rb', line 32 def one_to_many strategy_module.const_get('OneToMany') end |
#one_to_one ⇒ Object
28 29 30 |
# File 'lib/little_mapper/mapping_factory.rb', line 28 def one_to_one strategy_module.const_get('OneToOne') end |
#strategy ⇒ Object
8 9 10 |
# File 'lib/little_mapper/mapping_factory.rb', line 8 def strategy @_strategy end |
#strategy_module ⇒ Object
21 22 23 24 25 26 |
# File 'lib/little_mapper/mapping_factory.rb', line 21 def strategy_module case strategy when :activerecord ::LittleMapper::Mappers::AR end end |