Module: Verquest::Base::PrivateClassMethods Private
- Included in:
- Verquest::Base
- Defined in:
- lib/verquest/base/private_class_methods.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Private class methods for Verquest::Base
This module contains internal class methods used by the versioning system that are not intended for direct use by client code.
Instance Attribute Summary collapse
-
#current_scope ⇒ Verquest::Version, Verquest::Properties::Object
readonly
private
private
The current scope being defined.
-
#default_options ⇒ Hash
readonly
private
private
Default options used when using teh with_options method.
Instance Method Summary collapse
-
#array(name, type:, required: false, map: nil, **schema_options) ⇒ void
private
private
Defines a new array property for the current version scope.
-
#collection(name, item: nil, required: false, map: nil, **schema_options) { ... } ⇒ void
private
private
Defines a new collection for the current version scope.
-
#description(text) ⇒ void
private
private
Sets the description for the current version scope or globally.
-
#exclude_properties(*names) ⇒ void
private
private
Excludes specified properties from the current scope by removing them from the version’s property set.
-
#field(name, type: nil, map: nil, required: false, **schema_options) ⇒ void
private
private
Defines a new field for the current version scope.
-
#object(name, map: nil, required: false, **schema_options) { ... } ⇒ void
private
private
Defines a new object for the current version scope.
-
#reference(name, from:, property: nil, map: nil, required: false) ⇒ void
private
private
Defines a new reference for the current version scope.
-
#resolve(version) ⇒ Verquest::Version
private
Resolves the version to use, either from the provided version, configuration’s current_version, or raises an error if none is available.
-
#schema_options(**schema_options) ⇒ void
private
private
Sets additional schema options for the current version scope or globally.
-
#version(name, inherit: true, exclude_properties: []) { ... } ⇒ void
private
private
Defines a new version with optional inheritance from another version.
-
#versions ⇒ Verquest::Versions
private
private
Returns the versions container, initializing it if needed.
-
#with_options(**options) { ... } ⇒ void
private
private
Executes the given block with the specified options, temporarily overriding the default options for the duration of the block.
Instance Attribute Details
#current_scope ⇒ Verquest::Version, Verquest::Properties::Object (readonly, private)
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.
Returns The current scope being defined.
30 31 32 |
# File 'lib/verquest/base/private_class_methods.rb', line 30 def current_scope @current_scope end |
#default_options ⇒ Hash (readonly, private)
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.
Default options used when using teh with_options method.
34 35 36 |
# File 'lib/verquest/base/private_class_methods.rb', line 34 def end |
Instance Method Details
#array(name, type:, required: false, map: nil, **schema_options) ⇒ void (private)
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.
Defines a new array property for the current version scope
225 226 227 228 229 230 231 232 233 234 |
# File 'lib/verquest/base/private_class_methods.rb', line 225 def array(name, type:, required: false, map: nil, **) camelize() type = .fetch(:type, type) required = .fetch(:required, required) = .except(:type, :required).merge() array = Properties::Array.new(name:, type:, required:, map:, **) current_scope.add(array) end |
#collection(name, item: nil, required: false, map: nil, **schema_options) { ... } ⇒ void (private)
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.
Defines a new collection for the current version scope
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/verquest/base/private_class_methods.rb', line 178 def collection(name, item: nil, required: false, map: nil, **, &block) if item.nil? && !block_given? raise ArgumentError, "item must be provided or a block must be given to define the collection" elsif !item.nil? && !block_given? && !(item <= Verquest::Base) raise ArgumentError, "item must be a child of Verquest::Base class or nil" unless type.is_a?(Verquest::Properties::Base) end camelize() required = .fetch(:required, required) = .except(:required).merge() collection = Properties::Collection.new(name:, item:, required:, map:, **) current_scope.add(collection) if block_given? previous_scope = current_scope @current_scope = collection instance_exec(&block) end ensure @current_scope = previous_scope if block_given? end |
#description(text) ⇒ void (private)
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.
Sets the description for the current version scope or globally
76 77 78 79 80 81 82 83 84 |
# File 'lib/verquest/base/private_class_methods.rb', line 76 def description(text) if current_scope.nil? versions.description = text elsif current_scope.is_a?(Version) current_scope.description = text else raise "Description can only be set within a version scope or globally" end end |
#exclude_properties(*names) ⇒ void (private)
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.
Excludes specified properties from the current scope by removing them from the version’s property set
241 242 243 244 245 |
# File 'lib/verquest/base/private_class_methods.rb', line 241 def exclude_properties(*names) names.each do |name| current_scope.remove(name) end end |
#field(name, type: nil, map: nil, required: false, **schema_options) ⇒ void (private)
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.
Defines a new field for the current version scope
128 129 130 131 132 133 134 135 136 137 |
# File 'lib/verquest/base/private_class_methods.rb', line 128 def field(name, type: nil, map: nil, required: false, **) camelize() type = .fetch(:type, type) required = .fetch(:required, required) = .except(:type, :required).merge() field = Properties::Field.new(name:, type:, map:, required:, **) current_scope.add(field) end |
#object(name, map: nil, required: false, **schema_options) { ... } ⇒ void (private)
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.
Defines a new object for the current version scope
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/verquest/base/private_class_methods.rb', line 147 def object(name, map: nil, required: false, **, &block) unless block_given? raise ArgumentError, "a block must be given to define the object" end camelize() required = .fetch(:required, required) = .except(:type, :required).merge() object = Properties::Object.new(name:, map:, required:, **) current_scope.add(object) if block_given? previous_scope = current_scope @current_scope = object instance_exec(&block) end ensure @current_scope = previous_scope if block_given? end |
#reference(name, from:, property: nil, map: nil, required: false) ⇒ void (private)
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.
Defines a new reference for the current version scope
210 211 212 213 214 215 |
# File 'lib/verquest/base/private_class_methods.rb', line 210 def reference(name, from:, property: nil, map: nil, required: false) required = .fetch(:required, required) reference = Properties::Reference.new(name:, from:, property:, map:, required:) current_scope.add(reference) end |
#resolve(version) ⇒ Verquest::Version
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.
Resolves the version to use, either from the provided version, configuration’s current_version, or raises an error if none is available
17 18 19 20 21 22 23 24 25 |
# File 'lib/verquest/base/private_class_methods.rb', line 17 def resolve(version) if version.nil? && Verquest.configuration.current_version version = instance_exec(&Verquest.configuration.current_version) elsif version.nil? raise ArgumentError, "Version must be provided or set by Verquest.configuration.current_version" end versions.resolve(version) end |
#schema_options(**schema_options) ⇒ void (private)
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.
Sets additional schema options for the current version scope or globally
91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/verquest/base/private_class_methods.rb', line 91 def (**) camelize() if current_scope.nil? versions. = elsif current_scope.is_a?(Version) current_scope. = else raise "Additional properties can only be set within a version scope or globally" end end |
#version(name, inherit: true, exclude_properties: []) { ... } ⇒ void (private)
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.
Defines a new version with optional inheritance from another version
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/verquest/base/private_class_methods.rb', line 50 def version(name, inherit: true, exclude_properties: [], &block) version = Version.new(name:) versions.add(version) if inherit && @current_scope version.copy_from(@current_scope, exclude_properties:) elsif inherit.is_a?(String) inherit_version = versions.resolve(inherit) version.copy_from(inherit_version, exclude_properties:) end = {} @current_scope = version instance_exec(&block) ensure version.description ||= versions.description version. = versions..merge(version.) version.prepare end |
#versions ⇒ Verquest::Versions (private)
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.
Returns the versions container, initializing it if needed
39 40 41 |
# File 'lib/verquest/base/private_class_methods.rb', line 39 def versions @versions ||= Versions.new end |
#with_options(**options) { ... } ⇒ void (private)
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.
Executes the given block with the specified options, temporarily overriding the default options for the duration of the block
109 110 111 112 113 114 115 116 117 118 |
# File 'lib/verquest/base/private_class_methods.rb', line 109 def (**, &block) camelize() = = .except(:map) instance_exec(&block) ensure = end |