Module: Flatter::Mapper::Target::FactoryMethods

Included in:
Factory
Defined in:
lib/flatter/mapper/target.rb

Instance Method Summary collapse

Instance Method Details

#fetch_target_from(mapper) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/flatter/mapper/target.rb', line 12

def fetch_target_from(mapper)
  return super unless options.key?(:target)

  target = options[:target]

  case target
  when Proc then target.(mapper.target)
  when String, Symbol
    (mapper.private_methods + mapper.protected_methods + mapper.public_methods).include?(target.to_sym) ?
      mapper.send(target) :
      fail(ArgumentError, "Cannot use target #{target.inspect} with `#{mapper.name}`. Make sure #{target.inspect} is defined for #{mapper}")
  else target
  end
end