Commit d6e9ad6

mo khan <mo@mokhan.ca>
2022-12-09 17:56:04
refactor: extract type.fully_qualified_name
1 parent a0ae126
Changed files (3)
lib/scim/kit/v2/templates/resource.json.jbuilder
@@ -18,7 +18,7 @@ schemas.each do |schema|
   else
     json.set! schema.id do
       schema.attributes.each do |type|
-        attribute = dynamic_attributes["#{type.schema.id}##{type.name}"] ||
+        attribute = dynamic_attributes[type.fully_qualified_name] ||
                     dynamic_attributes[type.name]
         render attribute, json: json
       end
lib/scim/kit/v2/attributable.rb
@@ -88,13 +88,13 @@ module Scim
         end
 
         def attribute(type, resource)
-          key = type.name
-          if dynamic_attributes.key?(type.name)
-            key = "#{type.schema&.id}##{type.name}"
+          name = type.name
+          if dynamic_attributes.key?(name)
+            name = type.fully_qualified_name
           else
             extend(create_module_for(type))
           end
-          dynamic_attributes[key] = Attribute.new(
+          dynamic_attributes[name] = Attribute.new(
             type: type,
             resource: resource
           )
lib/scim/kit/v2/attribute_type.rb
@@ -8,11 +8,12 @@ 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, :schema
 
         def initialize(name:, type: :string, schema: nil)
           @name = name.to_s.underscore
+          @fully_qualified_name = schema ? "#{schema&.id}##{@name}" : @name
           @type = DATATYPES[type.to_sym] ? type.to_sym : (raise TYPE_ERROR)
           @schema = schema
           @description = name.to_s.camelize(:lower)