class Minimapper::Mapper::HasManyAssociation

Public Instance Methods

persist_changes() click to toggle source
# File lib/minimapper/mapper/has_many_association.rb, line 13
def persist_changes
  remove_deleted
  create_or_update
end

Private Instance Methods

association() click to toggle source
# File lib/minimapper/mapper/has_many_association.rb, line 47
def association
  repository.public_send(association_name)
end
create_or_update() click to toggle source
# File lib/minimapper/mapper/has_many_association.rb, line 28
def create_or_update
  current_entities.each do |entity|
    if entity.persisted?
      association.update(entity)
    else
      entity.public_send("#{belongs_to_association_name}=", parent_entity)
      association.create(entity)
    end
  end
end
current_entities() click to toggle source
# File lib/minimapper/mapper/has_many_association.rb, line 39
def current_entities
  parent_entity.public_send(association_name)
end
previous_entities() click to toggle source
# File lib/minimapper/mapper/has_many_association.rb, line 43
def previous_entities
  mapper.find(parent_entity.id).public_send(association_name)
end
remove_deleted() click to toggle source
# File lib/minimapper/mapper/has_many_association.rb, line 20
def remove_deleted
  previous_entities.each do |entity|
    unless current_entities.include?(entity)
      association.delete(entity)
    end
  end
end
repository() click to toggle source
# File lib/minimapper/mapper/has_many_association.rb, line 51
def repository
  mapper.repository
end