Sha256: 114ac39c6802432a4b68641dea58d368dc2e8a6651d4a197caa5470d21974150
Contents?: true
Size: 1.33 KB
Versions: 30
Compression:
Stored size: 1.33 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(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
30 entries across 30 versions & 1 rubygems