Class: HammerCLI::Options::Normalizers::Enum

Inherits:
AbstractNormalizer show all
Defined in:
lib/hammer_cli/options/normalizers.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from AbstractNormalizer

inherited

Constructor Details

#initialize(allowed_values) ⇒ Enum

Returns a new instance of Enum.



321
322
323
# File 'lib/hammer_cli/options/normalizers.rb', line 321

def initialize(allowed_values)
  @allowed_values = allowed_values
end

Instance Attribute Details

#allowed_valuesObject (readonly)

Returns the value of attribute allowed_values.



319
320
321
# File 'lib/hammer_cli/options/normalizers.rb', line 319

def allowed_values
  @allowed_values
end

Class Method Details

.common_descriptionObject



314
315
316
# File 'lib/hammer_cli/options/normalizers.rb', line 314

def common_description
  _("Possible values are described in the option's description")
end

.completion_typeObject



310
311
312
# File 'lib/hammer_cli/options/normalizers.rb', line 310

def completion_type
  :enum
end

Instance Method Details

#complete(value) ⇒ Object



342
343
344
# File 'lib/hammer_cli/options/normalizers.rb', line 342

def complete(value)
  Completer::finalize_completions(@allowed_values)
end

#completion_typeObject



346
347
348
# File 'lib/hammer_cli/options/normalizers.rb', line 346

def completion_type
  super.merge({ values: allowed_values })
end

#descriptionObject



325
326
327
# File 'lib/hammer_cli/options/normalizers.rb', line 325

def description
  _("Possible value(s): %s") % quoted_values
end

#format(value) ⇒ Object



329
330
331
332
333
334
335
336
337
338
339
340
# File 'lib/hammer_cli/options/normalizers.rb', line 329

def format(value)
  if @allowed_values.include? value
    value
  else
    if allowed_values.count == 1
      msg = _("Value must be %s.") % quoted_values
    else
      msg = _("Value must be one of %s.") % quoted_values
    end
    raise ArgumentError, msg
  end
end