Class: ActiveMocker::Collection::Base
- Inherits:
-
Object
- Object
- ActiveMocker::Collection::Base
- Includes:
- Enumerable
- Defined in:
- lib/active_mocker/collection/base.rb
Direct Known Subclasses
Instance Method Summary collapse
- #<<(*records) ⇒ Object
- #==(val) ⇒ Object
- #each(&block) ⇒ Object
-
#initialize(collection = []) ⇒ Base
constructor
A new instance of Base.
-
#order(key) ⇒ Object
def delete(obj) collection.delete(obj) end.
- #reverse_order ⇒ Object
- #select(&block) ⇒ Object
- #to_a ⇒ Object
Constructor Details
#initialize(collection = []) ⇒ Base
Returns a new instance of Base.
10 11 12 |
# File 'lib/active_mocker/collection/base.rb', line 10 def initialize(collection=[]) @collection = [*collection] end |
Instance Method Details
#<<(*records) ⇒ Object
14 15 16 |
# File 'lib/active_mocker/collection/base.rb', line 14 def <<(*records) collection.concat(records.flatten) end |
#==(val) ⇒ Object
47 48 49 50 |
# File 'lib/active_mocker/collection/base.rb', line 47 def ==(val) return false if val.nil? collection.hash == val.hash end |
#each(&block) ⇒ Object
37 38 39 40 41 |
# File 'lib/active_mocker/collection/base.rb', line 37 def each(&block) self.class.new(collection.each do |item| block.call(item) end) end |
#order(key) ⇒ Object
def delete(obj)
collection.delete(obj)
end
25 26 27 |
# File 'lib/active_mocker/collection/base.rb', line 25 def order(key) self.class.new(collection.sort_by{ |item| item.send(key) }) end |
#reverse_order ⇒ Object
29 30 31 |
# File 'lib/active_mocker/collection/base.rb', line 29 def reverse_order self.class.new(collection.reverse) end |
#select(&block) ⇒ Object
33 34 35 |
# File 'lib/active_mocker/collection/base.rb', line 33 def select(&block) self.class.new(collection.select(&block)) end |
#to_a ⇒ Object
43 44 45 |
# File 'lib/active_mocker/collection/base.rb', line 43 def to_a @collection end |