Module: Scim::Kit::V2::Attributable

Includes:
Enumerable
Included in:
Attribute, Resource
Defined in:
lib/scim/kit/v2/attributable.rb

Overview

Represents a dynamic attribute that corresponds to a SCIM type

Instance Method Summary collapse

Instance Method Details

#assign_attributes(attributes = {}) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/scim/kit/v2/attributable.rb', line 18

def assign_attributes(attributes = {})
  attributes.each do |key, value|
    next if key.to_sym == :schemas

    if key.to_s.start_with?(Schemas::EXTENSION)
      assign_attributes(value)
    else
      write_attribute(key, value)
    end
  end
end

#attribute_for(name) ⇒ Object



30
31
32
# File 'lib/scim/kit/v2/attributable.rb', line 30

def attribute_for(name)
  dynamic_attributes[name.to_s.underscore] || UnknownAttribute.new(name)
end

#define_attributes_for(resource, types) ⇒ Object



14
15
16
# File 'lib/scim/kit/v2/attributable.rb', line 14

def define_attributes_for(resource, types)
  types.each { |x| attribute(x, resource) }
end

#dynamic_attributesObject



10
11
12
# File 'lib/scim/kit/v2/attributable.rb', line 10

def dynamic_attributes
  @dynamic_attributes ||= {}.with_indifferent_access
end

#eachObject



49
50
51
52
53
# File 'lib/scim/kit/v2/attributable.rb', line 49

def each
  dynamic_attributes.each do |_name, attribute|
    yield attribute
  end
end

#read_attribute(name) ⇒ Object



34
35
36
37
38
39
# File 'lib/scim/kit/v2/attributable.rb', line 34

def read_attribute(name)
  attribute = attribute_for(name)
  return attribute._value if attribute._type.multi_valued

  attribute._type.complex? ? attribute : attribute._value
end

#write_attribute(name, value) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/scim/kit/v2/attributable.rb', line 41

def write_attribute(name, value)
  if value.is_a?(Hash)
    attribute_for(name)&.assign_attributes(value)
  else
    attribute_for(name)._value = value
  end
end