Class: Cuprum::Collections::Basic::Scopes::CriteriaScope

Inherits:
Base show all
Includes:
Scopes::Criteria
Defined in:
lib/cuprum/collections/basic/scopes/criteria_scope.rb

Overview

Scope for filtering on basic collection data based on criteria.

Instance Attribute Summary

Attributes included from Scopes::Criteria

#criteria

Instance Method Summary collapse

Methods included from Scopes::Criteria

#==, #and, #as_json, #debug, #empty?, #initialize, #invert, #inverted?, #or, #type, #with_criteria

Methods inherited from Base

#call

Methods inherited from Scopes::Base

#==, #as_json, #debug, #empty?, #initialize, #invert, #type

Methods included from Scopes::Composition

#and, #not, #or

Instance Method Details

#match?(item:) ⇒ Boolean Also known as: matches?

Returns true if the provided item matches the configured criteria.

Returns:

  • (Boolean)


51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/cuprum/collections/basic/scopes/criteria_scope.rb', line 51

def match?(item:)
  super

  if inverted?
    criteria.any? do |(attribute, operator, value)|
      filter_for(operator).call(item, attribute, value)
    end
  else
    criteria.all? do |(attribute, operator, value)|
      filter_for(operator).call(item, attribute, value)
    end
  end
end