Class: ActivePStore::Collection
- Inherits:
-
Object
- Object
- ActivePStore::Collection
show all
- Defined in:
- lib/active_pstore/collection.rb
Instance Method Summary
collapse
Constructor Details
#initialize(objects) ⇒ Collection
Returns a new instance of Collection.
3
4
5
|
# File 'lib/active_pstore/collection.rb', line 3
def initialize(objects)
@objects = objects
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
29
30
31
|
# File 'lib/active_pstore/collection.rb', line 29
def method_missing(method_name, *args, &block)
@objects.__send__(method_name, *args, &block)
end
|
Instance Method Details
#==(comparison_object) ⇒ Object
Also known as:
eql?
33
34
35
|
# File 'lib/active_pstore/collection.rb', line 33
def ==(comparison_object)
comparison_object.instance_of?(self.class) && self.map(&:id) <=> comparison_object.map(&:id)
end
|
#count ⇒ Object
21
22
23
|
# File 'lib/active_pstore/collection.rb', line 21
def count
@objects.count
end
|
#destroy_all ⇒ Object
13
14
15
16
17
18
19
|
# File 'lib/active_pstore/collection.rb', line 13
def destroy_all
@objects.inject(0) {|result, obj|
obj.destroy
result += 1
}
end
|
#empty? ⇒ Boolean
25
26
27
|
# File 'lib/active_pstore/collection.rb', line 25
def empty?
@objects.empty?
end
|
#hash ⇒ Object
38
39
40
41
42
43
44
|
# File 'lib/active_pstore/collection.rb', line 38
def hash
if id
id.hash
else
super
end
end
|
#update_all(updates) ⇒ Object
7
8
9
10
11
|
# File 'lib/active_pstore/collection.rb', line 7
def update_all(updates)
@objects.each {|obj|
obj.update_attributes(updates)
}.count
end
|