Class: ParamsReady::Parameter::TupleParameterDefinition

Inherits:
Definition show all
Includes:
ArrayParameterDefinition::ArrayLike
Defined in:
lib/params_ready/parameter/tuple_parameter.rb

Defined Under Namespace

Classes: StringMarshaller, StructMarshaller

Instance Attribute Summary

Attributes inherited from Definition

#default

Attributes inherited from AbstractDefinition

#altn, #name

Instance Method Summary collapse

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

#obligatory, #obligatory!

Methods included from Extensions::ClassReaderWriter

#class_reader_writer

Methods included from Extensions::LateInit

#late_init

Methods included from Extensions::Collection

#collection

Methods included from Extensions::Finalizer::InstanceMethods

#finish

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, **options)
  @fields = []
  add_fields fields unless fields.nil?
  super *args, **options
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

#arityObject



134
135
136
# File 'lib/params_ready/parameter/tuple_parameter.rb', line 134

def arity
  @fields.length
end

#ensure_canonical(array) ⇒ Object

Raises:



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

#freezeObject



146
147
148
149
# File 'lib/params_ready/parameter/tuple_parameter.rb', line 146

def freeze
  @fields.freeze
  super
end