Class: Preserves::Mapper

Inherits:
Object
  • Object
show all
Defined in:
lib/preserves/mapper.rb,
lib/preserves/mapper/has_many.rb,
lib/preserves/mapper/relation.rb,
lib/preserves/mapper/belongs_to.rb

Defined Under Namespace

Classes: BelongsTo, HasMany, Relation

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mapping) ⇒ Mapper

Returns a new instance of Mapper.



13
14
15
# File 'lib/preserves/mapper.rb', line 13

def initialize(mapping)
  self.mapping = mapping
end

Instance Attribute Details

#mappingObject

Returns the value of attribute mapping.



11
12
13
# File 'lib/preserves/mapper.rb', line 11

def mapping
  @mapping
end

Instance Method Details

#map(result, relations = {}) ⇒ Object



17
18
19
20
21
# File 'lib/preserves/mapper.rb', line 17

def map(result, relations={})
  result.map do |record|
    map_one(record, relations)
  end
end

#map_one(record, relations = {}) ⇒ Object



23
24
25
26
27
28
# File 'lib/preserves/mapper.rb', line 23

def map_one(record, relations={})
  mapping.model_class.new.tap do |object|
    map_attributes(object, record)
    map_relations(object, record, relations)
  end
end