class Scim::Kit::V2::Attribute

Represents a SCIM Attribute

Attributes

_resource[R]
_type[R]
_value[R]

Public Class Methods

new(resource:, type:, value: nil) click to toggle source
# File lib/scim/kit/v2/attribute.rb, line 23
def initialize(resource:, type:, value: nil)
  @_type = type
  @_value = value || type.multi_valued ? [] : nil
  @_resource = resource

  define_attributes_for(resource, type.attributes)
end

Public Instance Methods

_assign(new_value, coerce: false) click to toggle source
# File lib/scim/kit/v2/attribute.rb, line 31
def _assign(new_value, coerce: false)
  @_value = coerce ? _type.coerce(new_value) : new_value
end
_value=(new_value) click to toggle source
# File lib/scim/kit/v2/attribute.rb, line 35
def _value=(new_value)
  _assign(new_value, coerce: true)
end
each_value(&block) click to toggle source
# File lib/scim/kit/v2/attribute.rb, line 47
def each_value(&block)
  Array(_value).each(&block)
end
renderable?() click to toggle source
# File lib/scim/kit/v2/attribute.rb, line 39
def renderable?
  return false if server_only?
  return false if client_only?
  return false if restricted?

  true
end

Private Instance Methods

client_only?() click to toggle source
# File lib/scim/kit/v2/attribute.rb, line 57
def client_only?
  write_only? && (_resource.mode?(:server) || _value.blank?)
end
inclusion_of_value() click to toggle source
# File lib/scim/kit/v2/attribute.rb, line 71
def inclusion_of_value
  return if _type.canonical_values.include?(_value)

  errors.add(_type.name, I18n.t('errors.messages.inclusion'))
end
multiple() click to toggle source
# File lib/scim/kit/v2/attribute.rb, line 88
def multiple
  return unless _value.respond_to?(:to_a)

  duped_type = _type.dup
  duped_type.multi_valued = false
  _value.to_a.each do |x|
    unless duped_type.valid?(x)
      errors.add(duped_type.name, I18n.t('errors.messages.invalid'))
    end
  end
end
presence_of_value() click to toggle source
# File lib/scim/kit/v2/attribute.rb, line 65
def presence_of_value
  return unless _type.required && _value.blank?

  errors.add(_type.name, I18n.t('errors.messages.blank'))
end
read_only?() click to toggle source
# File lib/scim/kit/v2/attribute.rb, line 100
def read_only?
  _type.mutability == Mutability::READ_ONLY
end
restricted?() click to toggle source
# File lib/scim/kit/v2/attribute.rb, line 61
def restricted?
  _resource.mode?(:server) && _type.returned == Returned::NEVER
end
server_only?() click to toggle source
# File lib/scim/kit/v2/attribute.rb, line 53
def server_only?
  read_only? && _resource.mode?(:client)
end
validate_complex() click to toggle source
# File lib/scim/kit/v2/attribute.rb, line 84
def validate_complex
  validates_with ComplexAttributeValidator
end
validate_type() click to toggle source
# File lib/scim/kit/v2/attribute.rb, line 77
def validate_type
  return if _value.nil?
  return if _type.valid?(_value)

  errors.add(_type.name, I18n.t('errors.messages.invalid'))
end
write_only?() click to toggle source
# File lib/scim/kit/v2/attribute.rb, line 104
def write_only?
  _type.mutability == Mutability::WRITE_ONLY
end