Sha256: fa965088da8e4ed337b9c2b0b771cf84faea48da64d6aa05c968a8f92a23a9c1

Contents?: true

Size: 811 Bytes

Versions: 2

Compression:

Stored size: 811 Bytes

Contents

module Toy
  module Querying
    extend ActiveSupport::Concern

    module ClassMethods
      def get(id)
        value = store.read(id)
        log_operation(:get, self, store, id, value)
        load(id, value)
      end

      def get!(id)
        get(id) || raise(Toy::NotFound.new(id))
      end

      def get_multi(*ids)
        ids.flatten.map { |id| get(id) }
      end

      def get_or_new(id)
        get(id) || new(:id => id)
      end

      def get_or_create(id)
        get(id) || create(:id => id)
      end

      def key?(id)
        value = store.key?(id)
        log_operation(:key, self, store, id, value)
        value
      end
      alias :has_key? :key?

      def load(id, attrs)
        attrs && allocate.initialize_from_database(attrs.update('id' => id))
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
toystore-0.8.0 lib/toy/querying.rb
toystore-0.7.0 lib/toy/querying.rb