Sha256: cb402860ecd079bab74d1504e5004feada09ee374785befe1c1b158f00681419
Contents?: true
Size: 1.67 KB
Versions: 3
Compression:
Stored size: 1.67 KB
Contents
require 'superstore/scope/batches' require 'superstore/scope/finder_methods' require 'superstore/scope/query_methods' module Superstore class Scope include Batches, FinderMethods, QueryMethods attr_accessor :klass attr_accessor :limit_value, :select_values, :where_values, :id_values, :order_values def initialize(klass) @klass = klass @limit_value = nil @select_values = [] @where_values = [] @order_values = [] @id_values = [] reset end def initialize_copy(other) @limit_value = @limit_value.dup if @limit_value @select_values = @select_values.dup @where_values = @where_values.dup @order_values = @order_values.dup @id_values = @id_values.dup reset end def reset @records = nil @loaded = false end private def scoping previous, klass.current_scope = klass.current_scope, self yield ensure klass.current_scope = previous end def method_missing(method_name, *args, &block) if klass.respond_to?(method_name) scoping { klass.send(method_name, *args, &block) } elsif Array.method_defined?(method_name) to_a.send(method_name, *args, &block) else super end end def to_a unless @loaded @records = select_records @loaded = true end @records end def select_records results = [] klass.adapter.select(self) do |key, attributes| results << klass.instantiate(key, attributes) end results.compact! results end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
superstore-2.1.0 | lib/superstore/scope.rb |
superstore-2.0.1 | lib/superstore/scope.rb |
superstore-2.0.0 | lib/superstore/scope.rb |