Sha256: d7bef9b659949e92def1ebd11be908d91e01b828b1e3eab4781c21bc0437d065

Contents?: true

Size: 1.09 KB

Versions: 2

Compression:

Stored size: 1.09 KB

Contents

module Gummi
  module RepositoryLayer
    module Repository
      extend ActiveSupport::Concern

      included do
        include Repobahn::Repository
        after_conversion :set_id_and_version
      end

      module ClassMethods

        def get(id)
          document = db_class.get id
          db_instance_to_entity document if document
        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 set_id_and_version(entity, db_instance)
          entity.id      = db_instance.id
          entity.version = db_instance.version
        end

      end

    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
gummi-0.2.3 lib/gummi/repository_layer/repository.rb
gummi-0.2.2 lib/gummi/repository_layer/repository.rb