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: [], **options) ⇒ Resource

Returns a new instance of Resource.



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

def initialize(type:, attributes: [], **options)
  @type = type
  @options = options
  @attributes = ["id", "externalId", "displayName", *attributes]
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

#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

#query(**options) ⇒ Object



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

def query(**options)
  ResourcesQuery.new(Scim.client, resource: self,
                                  attributes: scim_attributes,
                                  **@options, **options)
end

#scim_attributesObject



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/audiences/scim/resource.rb', line 20

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