Class: Scimaenaga::ScimQueryParser

Inherits:
Object
  • Object
show all
Defined in:
app/models/scimaenaga/scim_query_parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(query_string, queryable_attributes) ⇒ ScimQueryParser

Returns a new instance of ScimQueryParser.



7
8
9
10
# File 'app/models/scimaenaga/scim_query_parser.rb', line 7

def initialize(query_string, queryable_attributes)
  self.query_elements = query_string.gsub(/\[(.+?)\]/, '.0').split
  self.query_attributes = queryable_attributes
end

Instance Attribute Details

#query_attributesObject

Returns the value of attribute query_attributes.



5
6
7
# File 'app/models/scimaenaga/scim_query_parser.rb', line 5

def query_attributes
  @query_attributes
end

#query_elementsObject

Returns the value of attribute query_elements.



5
6
7
# File 'app/models/scimaenaga/scim_query_parser.rb', line 5

def query_elements
  @query_elements
end

Instance Method Details

#attributeObject



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/models/scimaenaga/scim_query_parser.rb', line 12

def attribute
  attribute = query_elements[0]
  raise Scimaenaga::ExceptionHandler::InvalidQuery if attribute.blank?

  dig_keys = attribute.split('.').map do |step|
    step == '0' ? 0 : step.to_sym
  end

  mapped_attribute = query_attributes.dig(*dig_keys)
  raise Scimaenaga::ExceptionHandler::InvalidQuery if mapped_attribute.blank?

  mapped_attribute
end

#operatorObject



26
27
28
# File 'app/models/scimaenaga/scim_query_parser.rb', line 26

def operator
  sql_comparison_operator(query_elements[1])
end

#parameterObject



30
31
32
33
34
35
# File 'app/models/scimaenaga/scim_query_parser.rb', line 30

def parameter
  parameter = query_elements[2..-1].join(' ')
  return if parameter.blank?

  parameter.gsub(/"/, '')
end