Class: ParamsReady::Parameter::TupleParameterDefinition
- Inherits:
-
Definition
- Object
- AbstractDefinition
- Definition
- ParamsReady::Parameter::TupleParameterDefinition
- Includes:
- ArrayParameterDefinition::ArrayLike
- Defined in:
- lib/params_ready/parameter/tuple_parameter.rb
Direct Known Subclasses
Defined Under Namespace
Classes: StringMarshaller, StructMarshaller
Instance Attribute Summary
Attributes inherited from Definition
Attributes inherited from AbstractDefinition
Instance Method Summary collapse
- #add_fields(fields) ⇒ Object
- #arity ⇒ Object
- #ensure_canonical(array) ⇒ Object
- #freeze ⇒ Object
-
#initialize(*args, separator: nil, fields: nil, **options) ⇒ TupleParameterDefinition
constructor
A new instance of TupleParameterDefinition.
Methods included from ArrayParameterDefinition::ArrayLike
#duplicate_value, #freeze_value
Methods inherited from Definition
#canonical_default, #default_defined?, #fetch_callable_default, #fetch_default, #finish, #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, #finish, #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::Finalizer::InstanceMethods
Constructor Details
#initialize(*args, separator: nil, fields: nil, **options) ⇒ TupleParameterDefinition
Returns a new instance of TupleParameterDefinition.
113 114 115 116 117 |
# File 'lib/params_ready/parameter/tuple_parameter.rb', line 113 def initialize(*args, separator: nil, fields: nil, **) @fields = [] add_fields fields unless fields.nil? super *args, ** end |
Instance Method Details
#add_fields(fields) ⇒ Object
119 120 121 122 123 |
# File 'lib/params_ready/parameter/tuple_parameter.rb', line 119 def add_fields(fields) fields.each do |field| add_field(field) end end |
#arity ⇒ Object
134 135 136 |
# File 'lib/params_ready/parameter/tuple_parameter.rb', line 134 def arity @fields.length end |
#ensure_canonical(array) ⇒ Object
138 139 140 141 142 143 144 |
# File 'lib/params_ready/parameter/tuple_parameter.rb', line 138 def ensure_canonical(array) raise ParamsReadyError, "Not an array" unless array.is_a? Array context = Format.instance(:backend) marshaller = marshallers.instance(Array) value, _validator = marshaller.canonicalize(self, array, context, nil, freeze: true) value end |
#freeze ⇒ Object
146 147 148 149 |
# File 'lib/params_ready/parameter/tuple_parameter.rb', line 146 def freeze @fields.freeze super end |