Class: SmartCore::Types::Primitive::Factory::DefinitionContext Private
- Inherits:
-
Object
- Object
- SmartCore::Types::Primitive::Factory::DefinitionContext
- Defined in:
- lib/smart_core/types/primitive/factory/definition_context.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.
Instance Attribute Summary collapse
- #type_caster ⇒ Proc, NilClass readonly private
- #type_checker ⇒ Proc, NilClass readonly private
- #type_invariant_chains ⇒ Hash<String,Array<Proc>> readonly private
- #type_invariants ⇒ Hash<String,Proc> readonly private
- #type_runtime_attributes_checker ⇒ Proc, NilClass readonly private
Class Method Summary collapse
- .vaildate_invariant_attributes!(name, &definition) ⇒ void private
- .vaildate_invariant_chain_attributes!(chain_name, &definition) ⇒ void private
Instance Method Summary collapse
- #define_caster(&caster) ⇒ void
- #define_checker(&checker) ⇒ void
- #initialize ⇒ void constructor private
- #invariant(name, &definition) ⇒ void
- #invariant_chain(chain_name, &definitions) ⇒ void
- #runtime_attributes_checker(&definition) ⇒ void
Constructor Details
#initialize ⇒ 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.
93 94 95 96 97 98 99 100 |
# File 'lib/smart_core/types/primitive/factory/definition_context.rb', line 93 def initialize @type_invariant_chains = Hash.new { |h, k| h[k] = [] } @type_invariants = {} @type_checker = nil @type_caster = nil @type_runtime_attributes_checker = nil @definition_lock = SmartCore::Engine::Lock.new end |
Instance Attribute Details
#type_caster ⇒ Proc, NilClass (readonly)
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.
68 69 70 |
# File 'lib/smart_core/types/primitive/factory/definition_context.rb', line 68 def type_caster @type_caster end |
#type_checker ⇒ Proc, NilClass (readonly)
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.
62 63 64 |
# File 'lib/smart_core/types/primitive/factory/definition_context.rb', line 62 def type_checker @type_checker end |
#type_invariant_chains ⇒ Hash<String,Array<Proc>> (readonly)
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/factory/definition_context.rb', line 74 def type_invariant_chains @type_invariant_chains end |
#type_invariants ⇒ Hash<String,Proc> (readonly)
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.
80 81 82 |
# File 'lib/smart_core/types/primitive/factory/definition_context.rb', line 80 def type_invariants @type_invariants end |
#type_runtime_attributes_checker ⇒ Proc, NilClass (readonly)
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.
86 87 88 |
# File 'lib/smart_core/types/primitive/factory/definition_context.rb', line 86 def type_runtime_attributes_checker @type_runtime_attributes_checker end |
Class Method Details
.vaildate_invariant_attributes!(name, &definition) ⇒ 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.
This method returns an undefined value.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/smart_core/types/primitive/factory/definition_context.rb', line 15 def vaildate_invariant_attributes!(name, &definition) unless block_given? raise(SmartCore::Types::TypeDefinitionError, 'No invariant block') end unless name.is_a?(::String) || name.is_a?(::Symbol) raise(SmartCore::Types::TypeDefinitionError, <<~ERROR_MESSAGE) Invariant name should be a type of string or symbol. ERROR_MESSAGE end if name == '' || name == :"" raise(SmartCore::Types::TypeDefinitionError, <<~ERROR_MESSAGE) Invariant name can not be empty. ERROR_MESSAGE end end |
.vaildate_invariant_chain_attributes!(chain_name, &definition) ⇒ 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.
This method returns an undefined value.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/smart_core/types/primitive/factory/definition_context.rb', line 39 def vaildate_invariant_chain_attributes!(chain_name, &definition) unless block_given? raise(SmartCore::Types::TypeDefinitionError, 'No invariant chain block') end unless chain_name.is_a?(::String) || chain_name.is_a?(::Symbol) raise(SmartCore::Types::TypeDefinitionError, <<~ERROR_MESSAGE) Invariant chain name should be a type of string or symbol. ERROR_MESSAGE end if chain_name == '' || chain_name == :"" raise(SmartCore::Types::TypeDefinitionError, <<~ERROR_MESSAGE) Invariant chain name can not be empty. ERROR_MESSAGE end end |
Instance Method Details
#define_caster(&caster) ⇒ void
This method returns an undefined value.
123 124 125 126 127 128 129 130 |
# File 'lib/smart_core/types/primitive/factory/definition_context.rb', line 123 def define_caster(&caster) thread_safe do unless block_given? raise(SmartCore::Types::TypeDefinitionError, 'No caster definition block') end @type_caster = caster end end |
#define_checker(&checker) ⇒ void
This method returns an undefined value.
108 109 110 111 112 113 114 115 |
# File 'lib/smart_core/types/primitive/factory/definition_context.rb', line 108 def define_checker(&checker) thread_safe do unless block_given? raise(SmartCore::Types::TypeDefinitionError, 'No checker definition block') end @type_checker = checker end end |
#invariant(name, &definition) ⇒ void
This method returns an undefined value.
151 152 153 154 155 156 |
# File 'lib/smart_core/types/primitive/factory/definition_context.rb', line 151 def invariant(name, &definition) thread_safe do self.class.vaildate_invariant_attributes!(name, &definition) @type_invariants[name.to_s] = definition end end |
#invariant_chain(chain_name, &definitions) ⇒ void
This method returns an undefined value.
138 139 140 141 142 143 |
# File 'lib/smart_core/types/primitive/factory/definition_context.rb', line 138 def invariant_chain(chain_name, &definitions) thread_safe do self.class.vaildate_invariant_chain_attributes!(chain_name, &definitions) @type_invariant_chains[chain_name.to_s] << definitions end end |
#runtime_attributes_checker(&definition) ⇒ void
This method returns an undefined value.
163 164 165 166 167 168 169 170 |
# File 'lib/smart_core/types/primitive/factory/definition_context.rb', line 163 def runtime_attributes_checker(&definition) thread_safe do unless block_given? raise(SmartCore::Types::TypeDefinitionError, 'No runtime checker definition block') end @type_runtime_attributes_checker = definition end end |