class Scim::Kit::V2::Resource

Represents a SCIM Resource

Attributes

meta[R]
raw_attributes[R]
schemas[R]

Public Class Methods

new(schemas:, location: nil, attributes: {}) { |self| ... } click to toggle source
# File lib/scim/kit/v2/resource.rb, line 18
def initialize(schemas:, location: nil, attributes: {})
  @meta = Meta.new(schemas[0]&.name, location)
  @meta.disable_timestamps
  @schemas = schemas
  @raw_attributes = attributes
  schemas.each { |x| define_attributes_for(self, x.attributes) }
  attribute(AttributeType.new(name: :id), self)
  attribute(AttributeType.new(name: :external_id), self)
  assign_attributes(attributes)
  yield self if block_given?
end

Public Instance Methods

mode?(type) click to toggle source

Returns the current mode.

@param type [Symbol] The mode `:server` or `:client`. @return [Boolean] Returns true if the resource matches the # type of mode

# File lib/scim/kit/v2/resource.rb, line 34
def mode?(type)
  case type.to_sym
  when :server
    meta&.location
  else
    meta&.location.nil?
  end
end
template_name() click to toggle source

Returns the name of the jbuilder template file. @return [String] the name of the jbuilder template.

# File lib/scim/kit/v2/resource.rb, line 45
def template_name
  'resource.json.jbuilder'
end

Private Instance Methods

schema_validations() click to toggle source
# File lib/scim/kit/v2/resource.rb, line 51
def schema_validations
  schemas.each do |schema|
    schema.attributes.each do |type|
      validate_attribute(type)
    end
  end
end
validate_attribute(type) click to toggle source
# File lib/scim/kit/v2/resource.rb, line 59
def validate_attribute(type)
  attribute = attribute_for(type.name)
  errors.merge!(attribute.errors) unless attribute.valid?
end