lib/superstore/scope.rb in superstore-1.2.0 vs lib/superstore/scope.rb in superstore-2.0.0
- old
+ new
@@ -15,12 +15,28 @@
@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
@@ -34,9 +50,17 @@
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|