Class: Scim::Kit::V2::AttributeType
- Inherits:
-
Object
- Object
- Scim::Kit::V2::AttributeType
- Includes:
- Templatable
- Defined in:
- lib/scim/kit/v2/attribute_type.rb
Overview
Represents a scim Attribute type
Instance Attribute Summary collapse
-
#canonical_values ⇒ Object
Returns the value of attribute canonical_values.
-
#case_exact ⇒ Object
Returns the value of attribute case_exact.
-
#description ⇒ Object
Returns the value of attribute description.
-
#multi_valued ⇒ Object
Returns the value of attribute multi_valued.
-
#mutability ⇒ Object
Returns the value of attribute mutability.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#reference_types ⇒ Object
Returns the value of attribute reference_types.
-
#required ⇒ Object
Returns the value of attribute required.
-
#returned ⇒ Object
Returns the value of attribute returned.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#uniqueness ⇒ Object
Returns the value of attribute uniqueness.
Instance Method Summary collapse
- #add_attribute(name:, type: :string) {|attribute| ... } ⇒ Object
- #attributes ⇒ Object
- #coerce(value) ⇒ Object
- #complex? ⇒ Boolean
-
#initialize(name:, type: :string) ⇒ AttributeType
constructor
A new instance of AttributeType.
- #valid?(value) ⇒ Boolean
Methods included from Templatable
#as_json, #render, #template_name, #to_h, #to_json
Constructor Details
#initialize(name:, type: :string) ⇒ AttributeType
Returns a new instance of AttributeType.
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/scim/kit/v2/attribute_type.rb', line 20 def initialize(name:, type: :string) @name = name.to_s.underscore @type = type.to_sym @description = name @multi_valued = false @required = false @case_exact = false @mutability = Mutability::READ_WRITE @returned = Returned::DEFAULT @uniqueness = Uniqueness::NONE raise ArgumentError, :type unless DATATYPES[@type] end |
Instance Attribute Details
#canonical_values ⇒ Object
Returns the value of attribute canonical_values.
9 10 11 |
# File 'lib/scim/kit/v2/attribute_type.rb', line 9 def canonical_values @canonical_values end |
#case_exact ⇒ Object
Returns the value of attribute case_exact.
10 11 12 |
# File 'lib/scim/kit/v2/attribute_type.rb', line 10 def case_exact @case_exact end |
#description ⇒ Object
Returns the value of attribute description.
11 12 13 |
# File 'lib/scim/kit/v2/attribute_type.rb', line 11 def description @description end |
#multi_valued ⇒ Object
Returns the value of attribute multi_valued.
12 13 14 |
# File 'lib/scim/kit/v2/attribute_type.rb', line 12 def multi_valued @multi_valued end |
#mutability ⇒ Object
Returns the value of attribute mutability.
14 15 16 |
# File 'lib/scim/kit/v2/attribute_type.rb', line 14 def mutability @mutability end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
15 16 17 |
# File 'lib/scim/kit/v2/attribute_type.rb', line 15 def name @name end |
#reference_types ⇒ Object
Returns the value of attribute reference_types.
16 17 18 |
# File 'lib/scim/kit/v2/attribute_type.rb', line 16 def reference_types @reference_types end |
#required ⇒ Object
Returns the value of attribute required.
13 14 15 |
# File 'lib/scim/kit/v2/attribute_type.rb', line 13 def required @required end |
#returned ⇒ Object
Returns the value of attribute returned.
17 18 19 |
# File 'lib/scim/kit/v2/attribute_type.rb', line 17 def returned @returned end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
15 16 17 |
# File 'lib/scim/kit/v2/attribute_type.rb', line 15 def type @type end |
#uniqueness ⇒ Object
Returns the value of attribute uniqueness.
18 19 20 |
# File 'lib/scim/kit/v2/attribute_type.rb', line 18 def uniqueness @uniqueness end |
Instance Method Details
#add_attribute(name:, type: :string) {|attribute| ... } ⇒ Object
45 46 47 48 49 50 |
# File 'lib/scim/kit/v2/attribute_type.rb', line 45 def add_attribute(name:, type: :string) attribute = AttributeType.new(name: name, type: type) yield attribute if block_given? @type = :complex attributes << attribute end |
#attributes ⇒ Object
57 58 59 |
# File 'lib/scim/kit/v2/attribute_type.rb', line 57 def attributes @attributes ||= [] end |
#coerce(value) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/scim/kit/v2/attribute_type.rb', line 65 def coerce(value) return value if value.nil? return value if complex? if multi_valued return value unless value.respond_to?(:to_a) value.to_a.map do |x| COERCION.fetch(type, ->(y) { y }).call(x) end else COERCION.fetch(type, ->(x) { x }).call(value) end end |
#complex? ⇒ Boolean
61 62 63 |
# File 'lib/scim/kit/v2/attribute_type.rb', line 61 def complex? type_is?(:complex) end |
#valid?(value) ⇒ Boolean
80 81 82 83 84 85 86 87 88 |
# File 'lib/scim/kit/v2/attribute_type.rb', line 80 def valid?(value) if multi_valued return false unless value.respond_to?(:to_a) return value.to_a.all? { |x| validate(x) } end complex? ? valid_complex?(value) : valid_simple?(value) end |