Module: Scim::Kit::V2::Attributable
Overview
Represents a dynamic attribute that corresponds to a SCIM type
Instance Method Summary collapse
-
#assign_attributes(attributes = {}) ⇒ Object
Assigns attribute values via the provided hash.
-
#attribute_for(name) ⇒ Scim::Kit::V2::Attribute
Returns the attribute identified by the name.
-
#define_attributes_for(resource, types) ⇒ Object
Defines dynamic attributes on the resource for the types provided.
-
#dynamic_attributes ⇒ Hash
Returns a hash of the generated dynamic attributes.
-
#each(&block) ⇒ Object
yields each attribute to the provided block.
-
#read_attribute(name) ⇒ Object
Returns the value associated with the attribute name.
-
#write_attribute(name, value) ⇒ Object
Assigns the value to the attribute with the given name.
Instance Method Details
#assign_attributes(attributes = {}) ⇒ Object
Assigns attribute values via the provided hash.
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/scim/kit/v2/attributable.rb', line 25 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) ⇒ Scim::Kit::V2::Attribute
Returns the attribute identified by the name.
40 41 42 43 44 |
# File 'lib/scim/kit/v2/attributable.rb', line 40 def attribute_for(name) dynamic_attributes[name.to_s.underscore] || dynamic_attributes[name] || UnknownAttribute.new(name) end |
#define_attributes_for(resource, types) ⇒ Object
Defines dynamic attributes on the resource for the types provided
19 20 21 |
# File 'lib/scim/kit/v2/attributable.rb', line 19 def define_attributes_for(resource, types) types.each { |x| attribute(x, resource) } end |
#dynamic_attributes ⇒ Hash
Returns a hash of the generated dynamic attributes
12 13 14 |
# File 'lib/scim/kit/v2/attributable.rb', line 12 def dynamic_attributes @dynamic_attributes ||= {}.with_indifferent_access end |
#each(&block) ⇒ Object
yields each attribute to the provided block
69 70 71 |
# File 'lib/scim/kit/v2/attributable.rb', line 69 def each(&block) dynamic_attributes.each_value(&block) end |
#read_attribute(name) ⇒ Object
Returns the value associated with the attribute name
49 50 51 52 53 54 |
# File 'lib/scim/kit/v2/attributable.rb', line 49 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
Assigns the value to the attribute with the given name
59 60 61 62 63 64 65 |
# File 'lib/scim/kit/v2/attributable.rb', line 59 def write_attribute(name, value) if value.is_a?(Hash) attribute_for(name)&.assign_attributes(value) else attribute_for(name)._value = value end end |