Module: FlatMap::OpenMapper::Mapping

Extended by:
ActiveSupport::Concern
Included in:
FlatMap::OpenMapper
Defined in:
lib/flat_map/open_mapper/mapping.rb

Overview

This module hosts all definitions required to define and use mapping functionality within mapper classes. This includes mapping definition methods and basic reading and writing methods.

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#[](name) ⇒ Object

Retrieve mapping value via its name, which might differ from its full_name, if suffix was used.



93
94
95
# File 'lib/flat_map/open_mapper/mapping.rb', line 93

def [](name)
  mapping(name).try(:read)
end

#[]=(name, value) ⇒ Object

Write value to mapping specified by name, which might differ from its full_name, if suffix was used.



102
103
104
# File 'lib/flat_map/open_mapper/mapping.rb', line 102

def []=(name, value)
  mapping(name).try(:write, value)
end

#mapping(name) ⇒ FlatMap::Mapping

Lookup mapping by its name, which might differ from its full_name, if suffix was used.



111
112
113
# File 'lib/flat_map/open_mapper/mapping.rb', line 111

def mapping(name)
  mappings.find{ |mapping| mapping.name == name }
end

#readHash

Send read_as_params method to all mappings associated with self. And consolidate results in a single hash.



83
84
85
86
87
# File 'lib/flat_map/open_mapper/mapping.rb', line 83

def read
  mappings.inject({}) do |params, mapping|
    params.merge(mapping.read_as_params)
  end
end

#write(params) ⇒ Hash

Send passed params write_from_params method of each of the mappings of self.

Overloaded in FlatMap::OpenMapper::Mounting.



72
73
74
75
76
77
# File 'lib/flat_map/open_mapper/mapping.rb', line 72

def write(params)
  mappings.each do |mapping|
    mapping.write_from_params(params)
  end
  params
end