Commit a67f385
Changed files (5)
lib
scim
kit
v2
spec
scim
kit
lib/scim/kit/v2/templates/attribute.json.jbuilder
@@ -8,5 +8,5 @@ if type.complex? && !type.multi_valued
end
end
else
- json.set! type.name, _value
+ json.set! type.name, _value if renderable?
end
lib/scim/kit/v2/attributable.rb
@@ -7,9 +7,9 @@ module Scim
module Attributable
attr_reader :dynamic_attributes
- def define_attributes_for(types)
+ def define_attributes_for(resource, types)
@dynamic_attributes = {}.with_indifferent_access
- types.each { |x| attribute(x) }
+ types.each { |x| attribute(x, resource) }
end
private
@@ -42,8 +42,8 @@ module Scim
end
end
- def attribute(type)
- dynamic_attributes[type.name] = Attribute.new(type: type)
+ def attribute(type, resource)
+ dynamic_attributes[type.name] = Attribute.new(type: type, resource: resource)
extend(create_module_for(type))
end
end
lib/scim/kit/v2/attribute.rb
@@ -9,16 +9,18 @@ module Scim
include Attributable
include Templatable
attr_reader :type
+ attr_reader :_resource
attr_reader :_value
validate :presence_of_value, if: proc { |x| x.type.required }
validate :inclusion_of_value, if: proc { |x| x.type.canonical_values }
validate :validate_type
- def initialize(type:, value: nil)
+ def initialize(resource:, type:, value: nil)
@type = type
@_value = value
- define_attributes_for(type.attributes)
+ @_resource = resource
+ define_attributes_for(resource, type.attributes)
end
def _assign(new_value, coerce: true)
@@ -29,6 +31,10 @@ module Scim
_assign(new_value, coerce: true)
end
+ def renderable?
+ true
+ end
+
private
def presence_of_value
lib/scim/kit/v2/resource.rb
@@ -21,7 +21,7 @@ module Scim
@meta.disable_timestamps
@schemas = schemas
schemas.each do |schema|
- define_attributes_for(schema.attributes)
+ define_attributes_for(self, schema.attributes)
end
yield self if block_given?
end
spec/scim/kit/v2/attribute_spec.rb
@@ -1,7 +1,9 @@
# frozen_string_literal: true
RSpec.describe Scim::Kit::V2::Attribute do
- subject { described_class.new(type: type) }
+ subject { described_class.new(type: type, resource: resource) }
+ let(:resource) { Scim::Kit::V2::Resource.new(schemas: [schema], location: FFaker::Internet.uri('https')) }
+ let(:schema) { Scim::Kit::V2::Schema.new(id: Scim::Kit::V2::Schemas::USER, name: 'User', location: FFaker::Internet.uri('https')) }
context 'with strings' do
let(:type) { Scim::Kit::V2::AttributeType.new(name: 'userName', type: :string) }