Module: Flatter::Mapper::Collection::Concern

Extended by:
ActiveSupport::Concern
Defined in:
lib/flatter/mapper/collection.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#add_item(params) ⇒ Object



69
70
71
72
73
74
75
76
77
78
# File 'lib/flatter/mapper/collection.rb', line 69

def add_item(params)
  collection << clone.tap do |mapper|
    item = build_collection_item
    mapper.reset_locals!
    mapper.set_target!(item)
    mapper.item_index = collection.length
    mapper.write(params)
    add_item_to_target(item)
  end
end

#delete_target_item(item) ⇒ Object



61
62
63
# File 'lib/flatter/mapper/collection.rb', line 61

def delete_target_item(item)
  !!target.delete(item)
end

#update_item(key, params) ⇒ Object



65
66
67
# File 'lib/flatter/mapper/collection.rb', line 65

def update_item(key, params)
  collection.find{ |item| item[:key] == key }.write(params)
end