Method: FlatMap::OpenMapper::AttributeMethods#method_missing

Defined in:
lib/flat_map/open_mapper/attribute_methods.rb

#method_missing(name, *args, &block) ⇒ Object

Lazily define reader and writer methods for all mappings available to the mapper, and extend self with it.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/flat_map/open_mapper/attribute_methods.rb', line 14

def method_missing(name, *args, &block)
  if name == :to_ary ||
      @attribute_methods_defined ||
      self.class.protected_instance_methods.include?(name)
    return super
  end

  mappings    = all_mappings
  valid_names = mappings.map do |mapping|
    full_name = mapping.full_name
    [full_name, "#{full_name}=".to_sym]
  end
  valid_names.flatten!

  return super unless valid_names.include?(name)

  extend attribute_methods(mappings)
  @attribute_methods_defined = true
  send(name, *args, &block)
end