Class: Audiences::Scim::Resource

Inherits:
Object
  • Object
show all
Defined in:
lib/audiences/scim/resource.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type:, attributes: [], filter: nil, **options) ⇒ Resource

Returns a new instance of Resource.



8
9
10
11
12
13
# File 'lib/audiences/scim/resource.rb', line 8

def initialize(type:, attributes: [], filter: nil, **options)
  @type = type
  @options = options
  @attributes = ["id", "externalId", "displayName", *attributes]
  @filter = filter
end

Instance Attribute Details

#attributesObject

Returns the value of attribute attributes.



6
7
8
# File 'lib/audiences/scim/resource.rb', line 6

def attributes
  @attributes
end

#filterObject

Returns the value of attribute filter.



6
7
8
# File 'lib/audiences/scim/resource.rb', line 6

def filter
  @filter
end

#optionsObject

Returns the value of attribute options.



6
7
8
# File 'lib/audiences/scim/resource.rb', line 6

def options
  @options
end

#typeObject

Returns the value of attribute type.



6
7
8
# File 'lib/audiences/scim/resource.rb', line 6

def type
  @type
end

Instance Method Details

#allObject



23
24
25
# File 'lib/audiences/scim/resource.rb', line 23

def all(...)
  query(...).all
end

#merged_filter(filter) ⇒ Object



40
41
42
43
44
45
# File 'lib/audiences/scim/resource.rb', line 40

def merged_filter(filter)
  return @filter unless filter
  return filter unless @filter

  "(#{@filter}) and (#{filter})"
end

#query(**options) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/audiences/scim/resource.rb', line 15

def query(**options)
  options_filter = options.delete(:filter)
  ResourcesQuery.new(Scim.client, resource: self,
                                  attributes: scim_attributes,
                                  filter: merged_filter(options_filter),
                                  **@options, **options)
end

#scim_attributesObject



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/audiences/scim/resource.rb', line 27

def scim_attributes
  @attributes.reduce([]) do |attrs, attr|
    case attr
    when Hash
      attrs + attr.map do |key, nested_attrs|
        nested_attrs.map { "#{key}.#{_1}" }
      end
    else
      attrs + [attr]
    end
  end.join(",")
end