diff options
Diffstat (limited to 'lib/scim')
| -rw-r--r-- | lib/scim/kit/v2/attributable.rb | 13 | ||||
| -rw-r--r-- | lib/scim/kit/v2/attribute_type.rb | 9 | ||||
| -rw-r--r-- | lib/scim/kit/v2/schema.rb | 2 | ||||
| -rw-r--r-- | lib/scim/kit/v2/templates/resource.json.jbuilder | 3 | ||||
| -rw-r--r-- | lib/scim/kit/version.rb | 2 |
5 files changed, 15 insertions, 14 deletions
diff --git a/lib/scim/kit/v2/attributable.rb b/lib/scim/kit/v2/attributable.rb index 8584962..21d6431 100644 --- a/lib/scim/kit/v2/attributable.rb +++ b/lib/scim/kit/v2/attributable.rb @@ -38,7 +38,9 @@ module Scim # @param name [String] the name of the attribute to return # @return [Scim::Kit::V2::Attribute] the attribute or {Scim::Kit::V2::UnknownAttribute} def attribute_for(name) - dynamic_attributes[name.to_s.underscore] || UnknownAttribute.new(name) + dynamic_attributes[name.to_s.underscore] || + dynamic_attributes[name] || + UnknownAttribute.new(name) end # Returns the value associated with the attribute name @@ -86,11 +88,10 @@ module Scim end def attribute(type, resource) - dynamic_attributes[type.name] = Attribute.new( - type: type, - resource: resource - ) - extend(create_module_for(type)) + previously_defined = dynamic_attributes.key?(type.name) + dynamic_attributes[previously_defined ? type.fully_qualified_name : type.name] = + Attribute.new(type: type, resource: resource) + extend(create_module_for(type)) unless previously_defined end end end diff --git a/lib/scim/kit/v2/attribute_type.rb b/lib/scim/kit/v2/attribute_type.rb index a389281..b27a3a0 100644 --- a/lib/scim/kit/v2/attribute_type.rb +++ b/lib/scim/kit/v2/attribute_type.rb @@ -8,16 +8,15 @@ module Scim include Templatable attr_accessor :canonical_values, :case_exact, :description attr_accessor :multi_valued, :required - attr_reader :mutability, :name, :type, :attributes + attr_reader :mutability, :name, :fully_qualified_name, :type, :attributes attr_reader :reference_types, :returned, :uniqueness - def initialize(name:, type: :string) + def initialize(name:, type: :string, schema: nil) @name = name.to_s.underscore + @fully_qualified_name = [schema&.id, @name].compact.join('#') @type = DATATYPES[type.to_sym] ? type.to_sym : (raise TYPE_ERROR) @description = name.to_s.camelize(:lower) - @multi_valued = false - @required = false - @case_exact = false + @multi_valued = @required = @case_exact = false @mutability = Mutability::READ_WRITE @returned = Returned::DEFAULT @uniqueness = Uniqueness::NONE diff --git a/lib/scim/kit/v2/schema.rb b/lib/scim/kit/v2/schema.rb index 0cd6365..64576c4 100644 --- a/lib/scim/kit/v2/schema.rb +++ b/lib/scim/kit/v2/schema.rb @@ -21,7 +21,7 @@ module Scim end def add_attribute(name:, type: :string) - attribute = AttributeType.new(name: name, type: type) + attribute = AttributeType.new(name: name, type: type, schema: self) yield attribute if block_given? attributes << attribute end diff --git a/lib/scim/kit/v2/templates/resource.json.jbuilder b/lib/scim/kit/v2/templates/resource.json.jbuilder index 9545b26..3f8dfde 100644 --- a/lib/scim/kit/v2/templates/resource.json.jbuilder +++ b/lib/scim/kit/v2/templates/resource.json.jbuilder @@ -18,7 +18,8 @@ schemas.each do |schema| else json.set! schema.id do schema.attributes.each do |type| - attribute = dynamic_attributes[type.name] + attribute = dynamic_attributes[type.fully_qualified_name] || + dynamic_attributes[type.name] render attribute, json: json end end diff --git a/lib/scim/kit/version.rb b/lib/scim/kit/version.rb index 5ae9219..ba92e60 100644 --- a/lib/scim/kit/version.rb +++ b/lib/scim/kit/version.rb @@ -2,6 +2,6 @@ module Scim module Kit - VERSION = '0.7.0' + VERSION = '0.7.1' end end |
