Class: LittleMapper::MappingFactory

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

Instance Method Summary collapse

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_manyObject



32
33
34
# File 'lib/little_mapper/mapping_factory.rb', line 32

def one_to_many
  strategy_module.const_get('OneToMany')
end

#one_to_oneObject



28
29
30
# File 'lib/little_mapper/mapping_factory.rb', line 28

def one_to_one
  strategy_module.const_get('OneToOne')
end

#strategyObject



8
9
10
# File 'lib/little_mapper/mapping_factory.rb', line 8

def strategy
  @_strategy
end

#strategy_moduleObject



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