Class: Cuprum::Collections::Basic::Scopes::Base
- Inherits:
-
Scopes::Base
- Object
- Scopes::Base
- Cuprum::Collections::Basic::Scopes::Base
- Defined in:
- lib/cuprum/collections/basic/scopes/base.rb
Overview
Abstract class representing a set of filters for a basic query.
Direct Known Subclasses
AllScope, ConjunctionScope, CriteriaScope, DisjunctionScope, NoneScope
Instance Method Summary collapse
-
#call(data:) ⇒ Object
Filters the provided data.
-
#match?(item:) ⇒ Boolean
(also: #matches?)
Returns true if the provided item matches the scope.
Methods inherited from Scopes::Base
#==, #as_json, #debug, #empty?, #initialize, #invert, #type
Methods included from Scopes::Composition
Constructor Details
This class inherits a constructor from Cuprum::Collections::Scopes::Base
Instance Method Details
#call(data:) ⇒ Object
Filters the provided data.
10 11 12 13 14 |
# File 'lib/cuprum/collections/basic/scopes/base.rb', line 10 def call(data:) raise ArgumentError, 'data must be an Array' unless data.is_a?(Array) data.select { |item| match?(item:) } end |
#match?(item:) ⇒ Boolean Also known as: matches?
Returns true if the provided item matches the scope.
17 18 19 20 21 |
# File 'lib/cuprum/collections/basic/scopes/base.rb', line 17 def match?(item:) raise ArgumentError, 'item must be a Hash' unless item.is_a?(Hash) true end |