module Arpa::Repositories::Registrator

Public Instance Methods

create(entity) click to toggle source
# File lib/arpa/repositories/registrator.rb, line 6
def create(entity)
  save(entity, &:save!)
end
update(entity) click to toggle source
# File lib/arpa/repositories/registrator.rb, line 10
def update(entity)
  save(entity) do |record|
    record.updated_at = Time.new.utc
    attributes        = record.attributes.except('id', 'created_at')

    repository_class.update(entity.id, attributes)

    record.reload
    record.reload
    post_update(entity, record)
  end
end

Private Instance Methods

post_update(entity, record) click to toggle source
# File lib/arpa/repositories/registrator.rb, line 36
def post_update(entity, record); end
save(entity) { |record| ... } click to toggle source
# File lib/arpa/repositories/registrator.rb, line 25
def save(entity)
  record = mapper_instance.map_to_record(entity)
  begin
    yield(record)
  rescue ActiveRecord::RecordInvalid => invalid
    raise Arpa::Exceptions::RecordInvalid.new(message: invalid.message, errors: invalid.record.errors)
  end

  mapper_instance.map_to_entity(record)
end