Class: Diva::Type::AtomicType
Instance Attribute Summary
Attributes inherited from MetaType
#name
Instance Method Summary
collapse
Methods inherited from MetaType
#cast, #dump_for_json, #inspect, #to_s
Constructor Details
#initialize(name, recommended_class, *rest, &cast) ⇒ AtomicType
Returns a new instance of AtomicType.
81
82
83
84
|
# File 'lib/diva/type.rb', line 81
def initialize(name, recommended_class, *rest, &cast)
super(name, *rest, &cast)
@recommended_classes = Array(recommended_class)
end
|
Instance Method Details
#recommendation_point(value) ⇒ Object
86
87
88
89
|
# File 'lib/diva/type.rb', line 86
def recommendation_point(value)
_, point = @recommended_classes.map.with_index { |k, i| [k, i] }.find { |k, _| value.is_a?(k) }
point
end
|
#schema ⇒ Object
91
92
93
|
# File 'lib/diva/type.rb', line 91
def schema
@schema ||= { type: uri }.freeze
end
|
#uri ⇒ Object
95
96
97
|
# File 'lib/diva/type.rb', line 95
def uri
@uri ||= Diva::URI("diva://atomic.type/#{name}")
end
|