Class: Camille::Type
Overview
This class represents all custom types defined by the user.
Defined Under Namespace
Classes: NotImplementedError
Instance Attribute Summary collapse
Attributes inherited from BasicType
#fingerprint
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from BasicType
&, #&, #[], [], directly_instantiable?, instance, #transform, #|, |
Constructor Details
#initialize ⇒ Type
Returns a new instance of Type.
8
9
10
|
# File 'lib/camille/type.rb', line 8
def initialize
raise NotImplementedError.new("Missing `alias_of` definition for type.")
end
|
Instance Attribute Details
#underlying ⇒ Object
Returns the value of attribute underlying.
6
7
8
|
# File 'lib/camille/type.rb', line 6
def underlying
@underlying
end
|
Class Method Details
.alias_of(type) ⇒ Object
12
13
14
15
16
17
18
19
20
|
# File 'lib/camille/type.rb', line 12
def self.alias_of type
underlying = Camille::Type.instance(type)
fingerprint = underlying.fingerprint
define_method(:initialize) do
@underlying = underlying
@fingerprint = fingerprint
end
end
|
.inherited(klass) ⇒ Object
.klass_name ⇒ Object
36
37
38
|
# File 'lib/camille/type.rb', line 36
def self.klass_name
name.gsub(/^Camille::Types::/, '')
end
|
.test(value) ⇒ Object
32
33
34
|
# File 'lib/camille/type.rb', line 32
def self.test value
new.test value
end
|
Instance Method Details
#check(value) ⇒ Object
22
23
24
25
|
# File 'lib/camille/type.rb', line 22
def check value
normalized = transform value
@underlying.check normalized
end
|
#literal ⇒ Object
40
41
42
|
# File 'lib/camille/type.rb', line 40
def literal
self.class.klass_name.gsub(/::/, '_')
end
|
#test(value) ⇒ Object
27
28
29
30
|
# File 'lib/camille/type.rb', line 27
def test value
result = check value
result.type_error? ? result : nil
end
|