Class: ParamsReady::Parameter::ValueParameterBuilder

Inherits:
Builder show all
Extended by:
Extensions::Registry
Includes:
ValueLike
Defined in:
lib/params_ready/parameter/value_parameter.rb

Defined Under Namespace

Modules: ValueLike

Class Method Summary collapse

Methods included from Extensions::Registry

human_string, registry

Methods included from ValueLike

#coerce, #constrain, #format, #type_identifier

Methods inherited from Builder

#helper

Methods inherited from AbstractBuilder

#build, builder, define_parameter, define_registered_parameter, #fetch, fetch_builder, #include, #initialize, #open?, register, register_deprecated, resolve

Constructor Details

This class inherits a constructor from ParamsReady::AbstractBuilder

Class Method Details

.[](coder_name) ⇒ Object



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/params_ready/parameter/value_parameter.rb', line 88

def self.[](coder_name)
  builder = Class.new(self)
  capitalized = coder_name.to_s.split('_').map(&:capitalize).join
  qualified = "#{self.name}::#{capitalized}Builder".freeze

  builder.define_singleton_method :name do
    qualified
  end

  builder.define_singleton_method :instance do |name, altn: nil, **opts|
    superclass.instance(name, coder_name, altn: altn, **opts)
  end

  builder
end

.instance(name, coder_or_name = nil, altn: nil, **opts) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/params_ready/parameter/value_parameter.rb', line 73

def self.instance(name, coder_or_name = nil, altn: nil, **opts)
  coder = if coder_or_name.is_a? Symbol
    coder_class = self.coder(coder_or_name)
    coder_class.instance(**opts)
  else
    raise ParamsReadyError, 'Expected option hash to be empty' unless opts.empty?
    if coder_or_name.nil?
      Value::GenericCoder.new(name)
    else
      coder_or_name
    end
  end
  new ValueParameterDefinition.new(name, coder, altn: altn)
end