Class: Cliqr::Config::Option Private

Inherits:
Named show all
Defined in:
lib/cliqr/config/option.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.

Config attributes for a command’s option

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?, #set_config

Methods inherited from Base

#set_config, #skip_validation?

Methods included from Validation

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

Methods included from DSL

included

Constructor Details

#initializeOption

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.

Initialize a new config instance for an option with UNSET attribute values



42
43
44
45
46
47
48
49
# File 'lib/cliqr/config/option.rb', line 42

def initialize
  super

  @short = UNSET
  @type = UNSET
  @operator = UNSET
  @default = UNSET
end

Instance Attribute Details

#defaultObject

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.

Default value for this option

Returns:

  • (Object)


39
40
41
# File 'lib/cliqr/config/option.rb', line 39

def default
  @default
end

#operatorClass<Cliqr::Command::ArgumentOperator>

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.

Operation to be applied to the option value after validation



29
30
31
# File 'lib/cliqr/config/option.rb', line 29

def operator
  @operator
end

#shortString

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.

Optional short name for the option

Returns:

  • (String)


15
16
17
# File 'lib/cliqr/config/option.rb', line 15

def short
  @short
end

#typeSymbol

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.

Optional field that restricts values of this option to a certain type

Returns:

  • (Symbol)

    Type of the option



22
23
24
# File 'lib/cliqr/config/option.rb', line 22

def type
  @type
end

Instance Method Details

#boolean?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 a option is of boolean type

Returns:

  • (Boolean)

    true is the option is of type :boolean



83
84
85
# File 'lib/cliqr/config/option.rb', line 83

def boolean?
  @type == :boolean
end

#default?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 a default value setting is defined

Returns:

  • (Boolean)


90
91
92
# File 'lib/cliqr/config/option.rb', line 90

def default?
  !@default.nil?
end

#finalizeCliqr::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.

Finalize option’s config by adding default values for unset values



54
55
56
57
58
59
60
61
62
63
64
# File 'lib/cliqr/config/option.rb', line 54

def finalize
  super

  @short = Config.get_if_unset(@short, nil)
  @type = Config.get_if_unset(@type, ANY_ARGUMENT_TYPE)
  @operator = Util.ensure_instance(
    Config.get_if_unset(@operator, Cliqr::Command::ArgumentOperator.for_type(@type)))
  @default = Config.get_if_unset(@default, ARGUMENT_DEFAULTS[@type])

  self
end

#short?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 a option’s short name is defined

Returns:

  • (Boolean)

    true if options’ short name is not null neither empty



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

def short?
  !(@short.nil? || @short.empty?)
end

#type?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 a option’s type is defined

Returns:

  • (Boolean)

    true if options’ type is not nil and not equal to :any



76
77
78
# File 'lib/cliqr/config/option.rb', line 76

def type?
  !@type.nil? && @type != :any
end