Class: Bricolage::EnumParam

Inherits:
Param
  • Object
show all
Defined in:
lib/bricolage/parameters.rb

Instance Attribute Summary

Attributes inherited from Param

#arg_spec, #name

Instance Method Summary collapse

Methods inherited from Param

#have_arg?, #inspect, #option_name, #optional?, #parse_option_value, #parse_value, #publish?, #required?

Constructor Details

#initialize(name, list, description, default: nil, publish: false) ⇒ EnumParam

Returns a new instance of EnumParam.



419
420
421
422
423
# File 'lib/bricolage/parameters.rb', line 419

def initialize(name, list, description, default: nil, publish: false)
  super name, 'VALUE', description, optional: (default ? true : false), publish: publish
  @list = list.map {|val| val.to_s.freeze }
  @default_value = default
end

Instance Method Details

#default_value(ctx, vars) ⇒ Object



429
430
431
# File 'lib/bricolage/parameters.rb', line 429

def default_value(ctx, vars)
  @default_value
end

#descriptionObject



425
426
427
# File 'lib/bricolage/parameters.rb', line 425

def description
  "#{super} (#{@list.join(', ')})" + (@default ? " [default: #{@default}]" : '')
end

#materialize(value, ctx, vars) ⇒ Object



433
434
435
436
437
438
439
# File 'lib/bricolage/parameters.rb', line 433

def materialize(value, ctx, vars)
  val = expand(value.to_s, vars)
  unless @list.include?(val)
    raise ParameterError, "unknown value for enum parameter '#{name}': #{val.inspect}"
  end
  val
end

#variables(val) ⇒ Object



441
442
443
# File 'lib/bricolage/parameters.rb', line 441

def variables(val)
  wrap_variable_value(val)
end