Class: ParamsReady::Parameter::ArrayParameterDefinition
- Inherits:
-
Definition
- Object
- AbstractDefinition
- Definition
- ParamsReady::Parameter::ArrayParameterDefinition
- Includes:
- ArrayLike
- Defined in:
- lib/params_ready/parameter/array_parameter.rb
Direct Known Subclasses
Defined Under Namespace
Modules: ArrayLike
Instance Attribute Summary
Attributes inherited from Definition
Attributes inherited from AbstractDefinition
Instance Method Summary collapse
- #ensure_canonical(array) ⇒ Object
- #finish ⇒ Object
-
#initialize(*args, prototype: nil, **options) ⇒ ArrayParameterDefinition
constructor
A new instance of ArrayParameterDefinition.
- #set_default(args) ⇒ Object
- #try_canonicalize(value, context, validator = nil, freeze: false) ⇒ Object
Methods included from ArrayLike
#duplicate_value, #freeze_value
Methods inherited from Definition
#canonical_default, #default_defined?, #fetch_callable_default, #fetch_default, #memoize?, #name_for_formatter, #no_input?, #no_output?, #postprocess, #preprocess, #restricted_for_format?, #set_local, #set_no_input, #set_postprocessor, #set_preprocessor
Methods inherited from AbstractDefinition
#create, #from_hash, #from_input, #normalize_alternative_name, #parameter_class
Methods included from Extensions::Freezer
#freeze_variable, #freeze_variables, #variables_to_freeze
Methods included from Extensions::Finalizer
Methods included from Extensions::ClassReaderWriter
Methods included from Extensions::LateInit
Methods included from Extensions::Collection
Methods included from Extensions::Freezer::InstanceMethods
Constructor Details
#initialize(*args, prototype: nil, **options) ⇒ ArrayParameterDefinition
Returns a new instance of ArrayParameterDefinition.
155 156 157 158 159 |
# File 'lib/params_ready/parameter/array_parameter.rb', line 155 def initialize(*args, prototype: nil, **) raise ParamsReadyError, "Not a definition: #{prototype.class.name}" unless (prototype.is_a?(Definition) || prototype.nil?) @prototype = prototype super *args, ** end |
Instance Method Details
#ensure_canonical(array) ⇒ Object
173 174 175 176 177 178 |
# File 'lib/params_ready/parameter/array_parameter.rb', line 173 def ensure_canonical(array) raise "Not a canonical value, array expected, got: '#{array.class.name}'" unless array.is_a? Array context = Format.instance(:backend) value, _validator = try_canonicalize(array, context, nil, freeze: true) value end |
#finish ⇒ Object
189 190 191 192 193 194 |
# File 'lib/params_ready/parameter/array_parameter.rb', line 189 def finish if compact? && (prototype&.default_defined?) raise ParamsReadyError, 'Prototype must not be optional nor have default in compact array parameter' end super end |
#set_default(args) ⇒ Object
161 162 163 164 |
# File 'lib/params_ready/parameter/array_parameter.rb', line 161 def set_default(args) raise ParamsReadyError, "Can't set default before prototype has been defined" if @prototype.nil? super end |
#try_canonicalize(value, context, validator = nil, freeze: false) ⇒ Object
180 181 182 183 184 185 186 187 |
# File 'lib/params_ready/parameter/array_parameter.rb', line 180 def try_canonicalize(value, context, validator = nil, freeze: false) if freeze marshaller = marshallers.instance(Array) marshaller.canonicalize self, value, context, validator, freeze: freeze else super value, context, validator end end |