Sha256: 45a5460a7ab490f3c09ba38bdf98f40f3aecd0291e6de3e4d82ccaa54a1a1295
Contents?: true
Size: 1.34 KB
Versions: 17
Compression:
Stored size: 1.34 KB
Contents
require_relative 'concerns/key' require_relative 'memory/order' require_relative 'memory/condition' require_relative 'memory/query' require_relative 'memory/dataset' module Locomotive::Steam module Memory end class MemoryAdapter attr_accessor_initialize :collection include Locomotive::Steam::Adapters::Concerns::Key def all(mapper, scope) memoized_dataset(mapper, scope) end def query(mapper, scope, &block) _query(mapper, scope, &block) end def find(mapper, scope, id) _query(mapper, scope) { where(_id: id) }.first end def base_url(mapper, scope, entity = nil) '' end private def _query(mapper, scope, &block) Locomotive::Steam::Adapters::Memory::Query.new(all(mapper, scope), scope.locale, &block) end def memoized_dataset(mapper, scope) return @dataset if @dataset @dataset = dataset(mapper, scope) end def dataset(mapper, scope) Locomotive::Steam::Adapters::Memory::Dataset.new(mapper.name).tap do |dataset| collection.each do |attributes| # Note: very important to not manipulate the original attributes # since the attributes might be modified further by the to_entity method entity = mapper.to_entity(attributes.dup) dataset.insert(entity) end end end end end
Version data entries
17 entries across 17 versions & 1 rubygems