Class: Cuprum::Collections::Basic::Scopes::Base

Inherits:
Scopes::Base
  • Object
show all
Defined in:
lib/cuprum/collections/basic/scopes/base.rb

Overview

Abstract class representing a set of filters for a basic query.

Instance Method Summary collapse

Methods inherited from Scopes::Base

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

Methods included from Scopes::Composition

#and, #not, #or

Constructor Details

This class inherits a constructor from Cuprum::Collections::Scopes::Base

Instance Method Details

#call(data:) ⇒ Object

Filters the provided data.

Raises:

  • (ArgumentError)


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.

Returns:

  • (Boolean)

Raises:

  • (ArgumentError)


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