Class: Graphiti::Scoping::FilterGroupValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/graphiti/scoping/filter_group_validator.rb

Constant Summary collapse

VALID_REQUIRED_VALUES =
%i[all any]

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource, query_hash) ⇒ FilterGroupValidator

Returns a new instance of FilterGroupValidator.



16
17
18
19
# File 'lib/graphiti/scoping/filter_group_validator.rb', line 16

def initialize(resource, query_hash)
  @resource = resource
  @query_hash = query_hash
end

Class Method Details

.raise_unless_filter_group_requirement_valid!(resource, requirement) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# File 'lib/graphiti/scoping/filter_group_validator.rb', line 5

def self.raise_unless_filter_group_requirement_valid!(resource, requirement)
  unless VALID_REQUIRED_VALUES.include?(requirement)
    raise Errors::FilterGroupInvalidRequirement.new(
      resource,
      VALID_REQUIRED_VALUES
    )
  end

  true
end

Instance Method Details

#raise_unless_filter_group_requirements_met!Object



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/graphiti/scoping/filter_group_validator.rb', line 21

def raise_unless_filter_group_requirements_met!
  return if grouped_filters.empty?

  case filter_group_requirement
  when :all
    raise_unless_all_requirements_met!
  when :any
    raise_unless_any_requirements_met!
  end

  true
end