Sha256: 3937ea6559270baa9efdf0571606de075412a8f207829daf1159e5ed3f500e75

Contents?: true

Size: 971 Bytes

Versions: 10

Compression:

Stored size: 971 Bytes

Contents

module Arpa
  module Repositories
    module Registrator
      include Base

      def create(entity)
        save(entity) do |record|
          record.save!
        end
      end

      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

      def save(entity, &block)
        record = mapper_instance.map_to_record( entity)
        begin
          block.call(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

      def post_update(entity, record)
      end

    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
arpa-0.2.0 lib/arpa/repositories/registrator.rb
arpa-0.1.0 lib/arpa/repositories/registrator.rb
arpa-0.0.9 lib/arpa/repositories/registrator.rb
arpa-0.0.8 lib/arpa/repositories/registrator.rb
arpa-0.0.7 lib/arpa/repositories/registrator.rb
arpa-0.0.6 lib/arpa/repositories/registrator.rb
arpa-0.0.5 lib/arpa/repositories/registrator.rb
arpa-0.0.4 lib/arpa/repositories/registrator.rb
arpa-0.0.3 lib/arpa/repositories/registrator.rb
arpa-0.0.2 lib/arpa/repositories/registrator.rb