Class: Scim::Kit::V2::AttributeType
- Inherits:
-
Object
- Object
- Scim::Kit::V2::AttributeType
show all
- Includes:
- Templatable
- Defined in:
- lib/scim/kit/v2/attribute_type.rb
Overview
Represents a scim Attribute type
Instance Attribute Summary collapse
Instance Method Summary
collapse
#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
9
10
11
|
# File 'lib/scim/kit/v2/attribute_type.rb', line 9
def canonical_values
@canonical_values
end
|
#case_exact ⇒ Object
10
11
12
|
# File 'lib/scim/kit/v2/attribute_type.rb', line 10
def case_exact
@case_exact
end
|
#description ⇒ Object
11
12
13
|
# File 'lib/scim/kit/v2/attribute_type.rb', line 11
def description
@description
end
|
#multi_valued ⇒ Object
12
13
14
|
# File 'lib/scim/kit/v2/attribute_type.rb', line 12
def multi_valued
@multi_valued
end
|
#mutability ⇒ Object
14
15
16
|
# File 'lib/scim/kit/v2/attribute_type.rb', line 14
def mutability
@mutability
end
|
#name ⇒ Object
15
16
17
|
# File 'lib/scim/kit/v2/attribute_type.rb', line 15
def name
@name
end
|
#reference_types ⇒ Object
16
17
18
|
# File 'lib/scim/kit/v2/attribute_type.rb', line 16
def reference_types
@reference_types
end
|
#required ⇒ Object
13
14
15
|
# File 'lib/scim/kit/v2/attribute_type.rb', line 13
def required
@required
end
|
#returned ⇒ Object
17
18
19
|
# File 'lib/scim/kit/v2/attribute_type.rb', line 17
def returned
@returned
end
|
#type ⇒ Object
15
16
17
|
# File 'lib/scim/kit/v2/attribute_type.rb', line 15
def type
@type
end
|
#uniqueness ⇒ Object
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
|
# 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 { |x| coerce_single(x) }
else
coerce_single(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
78
79
80
81
82
83
84
85
86
|
# File 'lib/scim/kit/v2/attribute_type.rb', line 78
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
|