Class: HammerCLI::Options::Normalizers::Enum
- Inherits:
-
AbstractNormalizer
- Object
- AbstractNormalizer
- HammerCLI::Options::Normalizers::Enum
- Defined in:
- lib/hammer_cli/options/normalizers.rb
Instance Attribute Summary collapse
-
#allowed_values ⇒ Object
readonly
Returns the value of attribute allowed_values.
Class Method Summary collapse
Instance Method Summary collapse
- #complete(value) ⇒ Object
- #completion_type ⇒ Object
- #description ⇒ Object
- #format(value) ⇒ Object
-
#initialize(allowed_values) ⇒ Enum
constructor
A new instance of Enum.
Methods inherited from AbstractNormalizer
Constructor Details
#initialize(allowed_values) ⇒ Enum
Returns a new instance of Enum.
318 319 320 |
# File 'lib/hammer_cli/options/normalizers.rb', line 318 def initialize(allowed_values) @allowed_values = allowed_values end |
Instance Attribute Details
#allowed_values ⇒ Object (readonly)
Returns the value of attribute allowed_values.
316 317 318 |
# File 'lib/hammer_cli/options/normalizers.rb', line 316 def allowed_values @allowed_values end |
Class Method Details
.common_description ⇒ Object
311 312 313 |
# File 'lib/hammer_cli/options/normalizers.rb', line 311 def common_description _("Possible values are described in the option's description") end |
.completion_type ⇒ Object
307 308 309 |
# File 'lib/hammer_cli/options/normalizers.rb', line 307 def completion_type :enum end |
Instance Method Details
#complete(value) ⇒ Object
339 340 341 |
# File 'lib/hammer_cli/options/normalizers.rb', line 339 def complete(value) Completer::finalize_completions(@allowed_values) end |
#completion_type ⇒ Object
343 344 345 |
# File 'lib/hammer_cli/options/normalizers.rb', line 343 def completion_type super.merge({ values: allowed_values }) end |
#description ⇒ Object
322 323 324 |
# File 'lib/hammer_cli/options/normalizers.rb', line 322 def description _("Possible value(s): %s") % quoted_values end |
#format(value) ⇒ Object
326 327 328 329 330 331 332 333 334 335 336 337 |
# File 'lib/hammer_cli/options/normalizers.rb', line 326 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 |