module FlatMap::OpenMapper::Mapping

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.

Public Instance Methods

[](name) click to toggle source

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

@param [Symbol] name

# File lib/flat_map/open_mapper/mapping.rb, line 93
def [](name)
  mapping(name).try(:read)
end
[]=(name, value) click to toggle source

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

@param [Symbol] name @param [Object] value

# File lib/flat_map/open_mapper/mapping.rb, line 102
def []=(name, value)
  mapping(name).try(:write, value)
end
mapping(name) click to toggle source

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

@param [Symbol] name @return [FlatMap::Mapping]

# File lib/flat_map/open_mapper/mapping.rb, line 111
def mapping(name)
  mappings.find{ |mapping| mapping.name == name }
end
read() click to toggle source

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

@return [Hash] set of read values

# 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) click to toggle source

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

Overloaded in {OpenMapper::Mounting}.

@param [Hash] params @return [Hash] params

# 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

Private Instance Methods

mappings() click to toggle source

Return a list of mappings associated to self.

@return [FlatMap::Mapping]

# File lib/flat_map/open_mapper/mapping.rb, line 118
def mappings
  @mappings ||= self.class.mappings.map{ |factory| factory.create(self) }
end