Class: SmartCore::Types::Primitive
Private
- Inherits:
-
Object
- Object
- SmartCore::Types::Primitive
show all
- Defined in:
- lib/smart_core/types/primitive.rb
Overview
This class is part of a private API.
You should avoid using this class if possible, as it may be removed or be changed in the future.
Defined Under Namespace
Modules: MultFactory, NilableFactory, SumFactory
Classes: Caster, Checker, Factory, InvariantControl, MultValidator, NilableValidator, RuntimeAttributesChecker, SumValidator, UndefinedCaster, Validator
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(name, category, validator, caster, runtime_attributes_checker, *runtime_attributes) ⇒ void
This method is part of a private API.
You should avoid using this method if possible, as it may be removed or be changed in the future.
] rubocop:disable Metrics/ParameterLists
93
94
95
96
97
98
99
100
101
102
|
# File 'lib/smart_core/types/primitive.rb', line 93
def initialize(name, category, validator, caster, runtime_attributes_checker, *runtime_attributes)
@name = name
@category = category
@validator = validator
@caster = caster
@nilable = nil
@runtime_attributes_checker = runtime_attributes_checker
@runtime_attributes = runtime_attributes
@lock = SmartCore::Engine::Lock.new
end
|
Instance Attribute Details
This method is part of a private API.
You should avoid using this method if possible, as it may be removed or be changed in the future.
65
66
67
|
# File 'lib/smart_core/types/primitive.rb', line 65
def caster
@caster
end
|
This method is part of a private API.
You should avoid using this method if possible, as it may be removed or be changed in the future.
47
48
49
|
# File 'lib/smart_core/types/primitive.rb', line 47
def category
@category
end
|
#name ⇒ String, NilClass
Note:
NilClass is suitable for sum-types, mult-types and nilable types.
41
42
43
|
# File 'lib/smart_core/types/primitive.rb', line 41
def name
@name
end
|
#runtime_attributes ⇒ Array<Any>
This method is part of a private API.
You should avoid using this method if possible, as it may be removed or be changed in the future.
53
54
55
|
# File 'lib/smart_core/types/primitive.rb', line 53
def runtime_attributes
@runtime_attributes
end
|
This method is part of a private API.
You should avoid using this method if possible, as it may be removed or be changed in the future.
59
60
61
|
# File 'lib/smart_core/types/primitive.rb', line 59
def runtime_attributes_checker
@runtime_attributes_checker
end
|
This method is part of a private API.
You should avoid using this method if possible, as it may be removed or be changed in the future.
74
75
76
|
# File 'lib/smart_core/types/primitive.rb', line 74
def validator
@validator
end
|
Class Method Details
.define_type(type_name, &type_definition) {|type| ... } ⇒ SmartCore::Types::Primitive
31
32
33
|
# File 'lib/smart_core/types/primitive.rb', line 31
def define_type(type_name, &type_definition)
self::Factory.create_type(self, type_name, type_definition)
end
|
Instance Method Details
190
191
192
|
# File 'lib/smart_core/types/primitive.rb', line 190
def &(another_primitive)
self.class::MultFactory.create_type([self, another_primitive])
end
|
#cast(value) ⇒ Any
161
162
163
164
165
166
|
# File 'lib/smart_core/types/primitive.rb', line 161
def cast(value)
caster.call(value, runtime_attributes)
end
|
This method is part of a private API.
You should avoid using this method if possible, as it may be removed or be changed in the future.
110
111
112
113
114
|
# File 'lib/smart_core/types/primitive.rb', line 110
def initialize_copy(cloneable_instance)
lock.synchronize do
self.class::Factory::RuntimeTypeBuilder.initialize_clone(self, cloneable_instance)
end
end
|
172
173
174
|
# File 'lib/smart_core/types/primitive.rb', line 172
def nilable
lock.synchronize { @nilable ||= self.class::NilableFactory.create_type(self) }
end
|
#valid?(value) ⇒ Boolean
122
123
124
|
# File 'lib/smart_core/types/primitive.rb', line 122
def valid?(value)
validator.valid?(value)
end
|
151
152
153
|
# File 'lib/smart_core/types/primitive.rb', line 151
def validate(value)
validator.validate(value)
end
|
#validate!(value) ⇒ void
This method returns an undefined value.
138
139
140
|
# File 'lib/smart_core/types/primitive.rb', line 138
def validate!(value)
validator.validate!(value)
end
|
181
182
183
|
# File 'lib/smart_core/types/primitive.rb', line 181
def |(another_primitive)
self.class::SumFactory.create_type([self, another_primitive])
end
|