lib/active_enumerable/base.rb in active_enumerable-0.1.1 vs lib/active_enumerable/base.rb in active_enumerable-0.2.0
- old
+ new
@@ -1,12 +1,18 @@
module ActiveEnumerable
module Base
def initialize(collection=[])
- @to_a = collection.to_ary
+ if collection.is_a? ::Enumerator::Lazy
+ @collection = collection
+ else
+ @collection = collection.to_a
+ end
end
- attr_reader :to_a
+ def to_a
+ @collection.to_a
+ end
# @private
def __new_relation__(collection)
self.class.new(collection)
end
@@ -18,14 +24,18 @@
attributes
end)
end
def add(item)
- to_a << item
+ @collection << item
end
def all
- self
+ self.tap { to_a }
+ end
+
+ def name
+ self.class.name
end
module ClassMethods
def item_class
@item_class