Sha256: 9ea9fbca809768ae989e297a65e0b345a0baa58aa68fb3e234cf6419590c6c94

Contents?: true

Size: 1.17 KB

Versions: 3

Compression:

Stored size: 1.17 KB

Contents

module Gummi
  module RepositoryLayer
    module Repository
      extend ActiveSupport::Concern

      included do
        include Repobahn::Repository
        after_conversion :set_id_and_version
      end

      def get(id)
        return unless id
        document = db_class.get id
        db_instance_to_entity document if document
      end

      def delete(id)
        db_class.delete id
      end

      def search(options = {}, &block)
        search = db_class.new_filtered_search(options)
        yield search if block_given?
        Repository::Result.new search.execute, self
      end

      def raw_search(options = {}, &block)
        search = db_class.new_raw_search(options)
        yield search if block_given?
        Repository::Result.new search.execute, self
      end

      def overwrite(entity)
        return false unless entity.valid?
        document = db_class.new(entity.attributes)
        document.overwrite
      end

      def update(id, attributes)
        db_class.update id, attributes
      end

      def set_id_and_version(entity, db_instance)
        entity.id      = db_instance.id
        entity.version = db_instance.version
      end

    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
gummi-0.3.11 lib/gummi/repository_layer/repository.rb
gummi-0.3.10 lib/gummi/repository_layer/repository.rb
gummi-0.3.9 lib/gummi/repository_layer/repository.rb