Commit 6d381b7

mo <mo.khan@gmail.com>
2019-01-04 23:58:50
implement respond_to_missing?
1 parent cf1898d
Changed files (2)
lib/scim/kit/v2/templates/supportable.json.jbuilder
@@ -3,5 +3,5 @@
 json.key_format! camelize: :lower
 json.supported supported
 @custom_attributes.each do |key, value|
-  json.set! key, value
+  json.set! key.to_s.delete('='), value
 end
lib/scim/kit/v2/supportable.rb
@@ -3,24 +3,30 @@
 module Scim
   module Kit
     module V2
+      # Represents a Feature
       class Supportable
         include Templatable
 
         attr_accessor :supported
 
         def initialize(*custom_attributes)
-          @custom_attributes = Hash[custom_attributes.map { |x| [x, nil] }]
+          @custom_attributes = Hash[
+            custom_attributes.map { |x| ["#{x}=".to_sym, nil] }
+          ]
           @supported = false
         end
 
         def method_missing(method, *args)
-          target = method.to_s.delete('=').to_sym
-          if @custom_attributes.key?(target)
-            @custom_attributes[target] = args[0]
+          if respond_to_missing?(method)
+            @custom_attributes[method] = args[0]
           else
             super
           end
         end
+
+        def respond_to_missing?(method, _include_private = false)
+          @custom_attributes.key?(method)
+        end
       end
     end
   end