class Tsuga::Adapter::Memory::Base::Scope
Attributes
_filters[R]
_origin[R]
Public Class Methods
new(origin, filters)
click to toggle source
# File lib/tsuga/adapter/memory/base.rb, line 85 def initialize(origin, filters) @_origin = origin @_filters = filters end
Public Instance Methods
collect_ids()
click to toggle source
# File lib/tsuga/adapter/memory/base.rb, line 114 def collect_ids Set.new.tap do |result| _origin._records.each_value do |record| next unless _matches?(record) result << record.id end end end
delete_all()
click to toggle source
# File lib/tsuga/adapter/memory/base.rb, line 100 def delete_all _origin._records.each_pair do |id,record| next unless _matches?(record) _origin._records.delete(id) end end
find_by_id(id)
click to toggle source
# File lib/tsuga/adapter/memory/base.rb, line 94 def find_by_id(id) _origin.find_by_id(id).tap do |record| raise Tsuga::RecordNotFound unless _matches?(record) end end
find_each() { |clone| ... }
click to toggle source
# File lib/tsuga/adapter/memory/base.rb, line 107 def find_each _origin._records.dup.each_value do |record| next unless _matches?(record) yield record.clone end end
method_missing(method, *args)
click to toggle source
# File lib/tsuga/adapter/memory/base.rb, line 129 def method_missing(method, *args) result = _origin.send(method, *args) result = scoped(*(result._filters)) if result.kind_of?(Scope) end
respond_to?(method, include_private=false)
click to toggle source
Calls superclass method
# File lib/tsuga/adapter/memory/base.rb, line 134 def respond_to?(method, include_private=false) super || _origin.respond_to?(method, include_private) end
scoped(*filters)
click to toggle source
# File lib/tsuga/adapter/memory/base.rb, line 90 def scoped(*filters) Scope.new(_origin, _filters + filters) end
to_a()
click to toggle source
# File lib/tsuga/adapter/memory/base.rb, line 123 def to_a Array.new.tap do |ary| find_each { |record| ary << record } end end
Private Instance Methods
_matches?(record)
click to toggle source
# File lib/tsuga/adapter/memory/base.rb, line 140 def _matches?(record) _filters.all? { |f| f.call(record) } end