Class: Scim2::Filter::SimpleHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/scim2/filter/simple_handler.rb

Overview

Note:

This handler is intended only as a reference implementation for custom handlers and is otherwise not designed for production use.

Reference implementation of parser handler which captures parsed filters into a deeply nested Hash structure.

Examples:

# userName sw "J"

{
  sw: {
    path:   [:userName],
    schema: nil,
    value:  'J',
  },
}
# urn:ietf:params:scim:schemas:core:2.0:User:userType ne "Employee" and not (emails.value co "example.com" or emails.value co "example.org")

{
  and: [
    {
      ne: {
        path:   [:userType],
        schema: 'urn:ietf:params:scim:schemas:core:2.0:User',
        value:  'Employee',
      },
    },
    {
      not: {
        or: [
          {
            co: {
              path:   %i[emails value],
              schema: nil,
              value:  'example.com',
            },
          },
          {
            co: {
              path:   %i[emails value],
              schema: nil,
              value:  'example.org',
            },
          },
        ],
      },
    },
  ],
}
# emails[type eq "work"]

{
  path:   [:emails],
  schema: nil,
  nested: {
    eq: {
      path:   [:type],
      schema: nil,
      value:  'work',
    },
  },
}

Instance Method Summary collapse

Instance Method Details

#on_attribute_filter(attribute_path, value, context:, op:, schema: nil) ⇒ Hash<Symbol, Object>

Handle basic attribute comparison filters (e.g. preference.color eq "red")

Parameters:

  • attribute_path (Array<Symbol>)

    the attribute name(s) being filtered on, split by .

  • value (Object)

    the value being compared against

  • op (Object)

    the comparison operator (e.g. :eq)

  • schema (String) (defaults to: nil)

    schema namespace of the attribute

Returns:

  • (Hash<Symbol, Object>)

85
86
87
# File 'lib/scim2/filter/simple_handler.rb', line 85

def on_attribute_filter(attribute_path, value, context:, op:, schema: nil)
  { op => { path: attribute_path, value: value, schema: schema } }
end

#on_logical_filter(filter1, filter2, context:, op:) ⇒ Hash<Symbol, Object>

Handle logical filters (e.g. name.givenName sw "D" AND title co "VP")

Parameters:

  • filter1 (Hash<Symbol, Object>)

    the left-hand side filter

  • filter2 (Hash<Symbol, Object>)

    the right-hand side filter

  • op (Object)

    the logical operator (e.g. AND)

Returns:

  • (Hash<Symbol, Object>)

94
95
96
# File 'lib/scim2/filter/simple_handler.rb', line 94

def on_logical_filter(filter1, filter2, context:, op:)
  { op => [filter1, filter2] }
end

#on_nested_filter(attribute_path, filter, context:, schema: nil) ⇒ Hash<Symbol, Object>

Handle nested filters (e.g. emails[type eq "work"])

Parameters:

  • attribute_path (Array<Symbol>)

    the attribute name(s) being filtered on, split by .

  • filter (Hash<Symbol, Object>)

    the nested-filter inside the backets

  • schema (String) (defaults to: nil)

    schema namespace of the attribute

Returns:

  • (Hash<Symbol, Object>)

103
104
105
# File 'lib/scim2/filter/simple_handler.rb', line 103

def on_nested_filter(attribute_path, filter, context:, schema: nil)
  { path: attribute_path, nested: filter, schema: schema }
end

#on_not_filter(filter, context:) ⇒ Hash<Symbol, Object>

Handle NOT filters (e.g. not (color eq "red"))

Parameters:

  • filter (Hash<Symbol, Object>)

    the internal filter being NOT'ed

Returns:

  • (Hash<Symbol, Object>)

75
76
77
# File 'lib/scim2/filter/simple_handler.rb', line 75

def on_not_filter(filter, context:)
  { not: filter }
end