Class: Cliqr::Config::OptionBased Private

Inherits:
Named show all
Defined in:
lib/cliqr/config/option_based.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Configuration setting for an option based setting

Direct Known Subclasses

Action, Shell

Instance Attribute Summary collapse

Attributes inherited from Named

#description, #name

Attributes inherited from EventBased

#events

Instance Method Summary collapse

Methods inherited from Named

#description?, #name?

Methods inherited from EventBased

#event, #handle?

Methods inherited from Base

#skip_validation?

Methods included from Validation

#errors, included, #read_attributes, #valid?, #validate, #validations

Methods included from DSL

included

Constructor Details

#initializeOptionBased

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

New config instance with all attributes set as UNSET



22
23
24
25
26
27
# File 'lib/cliqr/config/option_based.rb', line 22

def initialize
  super

  @options = {}
  @short_option_index = {}
end

Instance Attribute Details

#optionsArray<OptionConfig>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Array of options applied to the base command

Returns:

  • (Array<OptionConfig>)


17
18
19
# File 'lib/cliqr/config/option_based.rb', line 17

def options
  @options
end

Instance Method Details

#finalizeCliqr::Config::OptionBased

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Finalize config by adding default values for unset values



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/cliqr/config/option_based.rb', line 32

def finalize
  super

  if options? && @short_option_index.empty?
    @options.values.each do |option|
      @short_option_index[option.short.to_s] = option if option.short?
    end
  end

  self
end

#option(name) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Get value of a option

Parameters:

  • name (String)

    Name of the option

Returns:

  • (String)

    value for the option



78
79
80
81
82
83
84
# File 'lib/cliqr/config/option_based.rb', line 78

def option(name)
  if @options.key?(name.to_s)
    @options[name.to_s]
  else
    @short_option_index[name.to_s]
  end
end

#option?(name) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Check if particular option is set

Parameters:

  • name (String)

    Name of the option to check

Returns:

  • (Boolean)


69
70
71
# File 'lib/cliqr/config/option_based.rb', line 69

def option?(name)
  @options.key?(name.to_s) || @short_option_index.key?(name.to_s)
end

#options?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Check if options are set

Returns:

  • (Boolean)


61
62
63
64
# File 'lib/cliqr/config/option_based.rb', line 61

def options?
  return false if @options.nil?
  !@options.empty?
end

#set_config(name, value, *args, &block) ⇒ Cliqr::Config::Option

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Set value for a config option

Parameters:

  • name (Symbol)

    Name of the config parameter

  • value (Object)

    Value for the config parameter

  • block (Proc)

    Function which populates configuration for a sub-attribute

Returns:



51
52
53
54
55
56
57
58
# File 'lib/cliqr/config/option_based.rb', line 51

def set_config(name, value, *args, &block)
  case name
  when :option
    handle_option(value, &block) # value is the long name for the option
  else
    super
  end
end