Class: Camille::BasicType
- Inherits:
-
Object
- Object
- Camille::BasicType
show all
- Defined in:
- lib/camille/basic_type.rb
Overview
This class specifies the methods available for all types includeing built-in and custom ones.
Direct Known Subclasses
PickAndOmit, Type, Types::Any, Types::Array, Types::Boolean, Types::BooleanLiteral, Types::Intersection, Types::Null, Types::Number, Types::NumberLiteral, Types::Object, Types::Record, Types::String, Types::StringLiteral, Types::Tuple, Types::Undefined, Types::Union
Defined Under Namespace
Modules: CheckRendered
Classes: InvalidTypeError, RenderError
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of BasicType.
25
26
27
|
# File 'lib/camille/basic_type.rb', line 25
def initialize
@fingerprint = Digest::MD5.hexdigest self.class.name
end
|
Instance Attribute Details
#fingerprint ⇒ Object
Returns the value of attribute fingerprint.
23
24
25
|
# File 'lib/camille/basic_type.rb', line 23
def fingerprint
@fingerprint
end
|
Class Method Details
.&(other) ⇒ Object
66
67
68
|
# File 'lib/camille/basic_type.rb', line 66
def self.& other
Camille::Type.instance(self) & other
end
|
.[] ⇒ Object
70
71
72
|
# File 'lib/camille/basic_type.rb', line 70
def self.[]
Camille::Type.instance(self)[]
end
|
.check_params(value) ⇒ Object
74
75
76
|
# File 'lib/camille/basic_type.rb', line 74
def self.check_params value
Camille::Type.instance(self).check_params value
end
|
.directly_instantiable? ⇒ Boolean
78
79
80
|
# File 'lib/camille/basic_type.rb', line 78
def self.directly_instantiable?
instance_method(:initialize).arity == 0
end
|
.inherited(klass) ⇒ Object
82
83
84
|
# File 'lib/camille/basic_type.rb', line 82
def self.inherited klass
klass.prepend CheckRendered
end
|
.instance(value) ⇒ Object
.|(other) ⇒ Object
62
63
64
|
# File 'lib/camille/basic_type.rb', line 62
def self.| other
Camille::Type.instance(self) | other
end
|
Instance Method Details
#check(value) ⇒ Object
54
55
56
|
# File 'lib/camille/basic_type.rb', line 54
def check value
raise NotImplementedError
end
|
#check_params(value) ⇒ Object
58
59
60
|
# File 'lib/camille/basic_type.rb', line 58
def check_params value
check value
end
|
#render!(value) ⇒ Object
Checks value and returns a Camille::Rendered, raising RenderError with
the printed type error if the check fails.
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/camille/basic_type.rb', line 31
def render! value
result = check(value)
if result.type_error?
string_io = StringIO.new
Camille::TypeErrorPrinter.new(result).print(string_io)
raise RenderError.new("\nType check failed for render!.\n#{string_io.string}")
else
result.render
end
end
|
#|(other) ⇒ Object
42
43
44
|
# File 'lib/camille/basic_type.rb', line 42
def | other
Camille::Types::Union.new(self, other)
end
|