Module: ViewSpec::Collection
- Extended by:
- ActiveSupport::Concern
- Includes:
- Enumerable
- Included in:
- EntryCollection
- Defined in:
- lib/view_spec/collection.rb
Instance Method Summary collapse
- #+(other) ⇒ Object
- #<<(item) ⇒ Object
- #find_where(conditions) ⇒ Object
- #find_where!(conditions) ⇒ Object
- #initialize(items = []) ⇒ Object
- #to_a ⇒ Object
- #where(conditions) ⇒ Object
Instance Method Details
#+(other) ⇒ Object
35 36 37 |
# File 'lib/view_spec/collection.rb', line 35 def +(other) self.class.new(items + other.items) end |
#<<(item) ⇒ Object
30 31 32 33 |
# File 'lib/view_spec/collection.rb', line 30 def <<(item) items.push(item) self end |
#find_where(conditions) ⇒ Object
15 16 17 |
# File 'lib/view_spec/collection.rb', line 15 def find_where(conditions) where(conditions).first end |
#find_where!(conditions) ⇒ Object
19 20 21 22 |
# File 'lib/view_spec/collection.rb', line 19 def find_where!(conditions) result = find_where(conditions) result.nil? ? raise("No matching item found for conditions #{conditions}") : result end |
#initialize(items = []) ⇒ Object
11 12 13 |
# File 'lib/view_spec/collection.rb', line 11 def initialize(items = []) @items = items.is_a?(Collection) ? items.to_a : items end |
#to_a ⇒ Object
39 40 41 |
# File 'lib/view_spec/collection.rb', line 39 def to_a items end |
#where(conditions) ⇒ Object
24 25 26 27 28 |
# File 'lib/view_spec/collection.rb', line 24 def where(conditions) conditions.reduce(items.dup) do |collection, (key, value)| collection.filter! { _1.respond_to?(key) && (_1.public_send(key) == value) } end end |