Class: Cliqr::Config::Action Private

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

Direct Known Subclasses

Command

Instance Attribute Summary collapse

Attributes inherited from OptionBased

#options

Attributes inherited from Named

#description, #name

Attributes inherited from EventBased

#events

Instance Method Summary collapse

Methods inherited from OptionBased

#option, #option?, #options?

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

#initializeAction

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



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

def initialize
  super

  @handler = UNSET
  @arguments = UNSET
  @help = UNSET

  @actions = []
  @action_index = {}
end

Instance Attribute Details

#actionsArray<Cliqr::CLI::Config>

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 children action configs for this action

Returns:

  • (Array<Cliqr::CLI::Config>)


34
35
36
# File 'lib/cliqr/config/action.rb', line 34

def actions
  @actions
end

#argumentsSymbol

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.

Dictates whether this command can take arbitrary arguments (optional)

Returns:

  • (Symbol)

    Either #ENABLE_CONFIG or #DISABLE_CONFIG



27
28
29
# File 'lib/cliqr/config/action.rb', line 27

def arguments
  @arguments
end

#handlerClass<Cliqr::Command::BaseCommand>

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.

Command handler for the base command

Returns:



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

def handler
  @handler
end

#helpSymbol

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.

Enable or disable help command and option

Returns:

  • (Symbol)

    Either #ENABLE_CONFIG or #DISABLE_CONFIG



41
42
43
# File 'lib/cliqr/config/action.rb', line 41

def help
  @help
end

#parentCliqr::Config::CommandConfig

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.

Parent configuration

Returns:

  • (Cliqr::Config::CommandConfig)


48
49
50
# File 'lib/cliqr/config/action.rb', line 48

def parent
  @parent
end

Instance Method Details

#action(name) ⇒ Cliqr::Config::Action

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 action config by name

Parameters:

  • name (String)

    Name of the action

Returns:



123
124
125
# File 'lib/cliqr/config/action.rb', line 123

def action(name)
  @action_index[name.to_sym]
end

#action?(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 action exists

Parameters:

  • name (String)

    Name of the action to check

Returns:

  • (Boolean)

    true if the action exists in the configuration



106
107
108
109
# File 'lib/cliqr/config/action.rb', line 106

def action?(name)
  return false if name.nil?
  @action_index.key?(name.to_sym)
end

#actions?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 this config has sub actions

Returns:

  • (Boolean)


114
115
116
# File 'lib/cliqr/config/action.rb', line 114

def actions?
  !@actions.empty?
end

#arguments?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 arguments are enabled for this configuration

Returns:

  • (Boolean)

    true if arguments are enabled



130
131
132
# File 'lib/cliqr/config/action.rb', line 130

def arguments?
  @arguments == ENABLE_CONFIG
end

#commandString

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 name of the command along with the action upto this config

Returns:

  • (String)

    Serialized command name



137
138
139
140
# File 'lib/cliqr/config/action.rb', line 137

def command
  return name unless parent?
  "#{@parent.command} #{name}"
end

#finalizeCliqr::Config::Action

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



65
66
67
68
69
70
71
72
73
# File 'lib/cliqr/config/action.rb', line 65

def finalize
  super

  @handler = Util.ensure_instance(Config.get_if_unset(@handler, nil))
  @arguments = Config.get_if_unset(@arguments, ENABLE_CONFIG)
  @help = Config.get_if_unset(@help, ENABLE_CONFIG)

  self
end

#help?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 help is enabled for this command

Returns:

  • (Boolean)

    true if help is enabled



152
153
154
# File 'lib/cliqr/config/action.rb', line 152

def help?
  @help == ENABLE_CONFIG
end

#parent?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 this config has a parent config

Returns:

  • (Boolean)

    true if there exists a parent action for this action



145
146
147
# File 'lib/cliqr/config/action.rb', line 145

def parent?
  !@parent.nil?
end

#rootCliqr::Config::Action

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.

The root of action config is itself unless otherwise configured



159
160
161
# File 'lib/cliqr/config/action.rb', line 159

def root
  self
end

#root?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 this action is the root

Returns:

  • (Boolean)


164
165
166
# File 'lib/cliqr/config/action.rb', line 164

def root?
  self == root
end

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

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:

  • (Object)

    if setting a attribute’s value

  • (Cliqr::Config::Base)

    if adding a new action or option



92
93
94
95
96
97
98
99
# File 'lib/cliqr/config/action.rb', line 92

def set_config(name, value, *args, &block)
  case name
  when :action
    handle_action(value, &block) # value is action's name
  else
    super
  end
end

#setup_defaultsCliqr::Config::Command

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 up default attributes for this configuration

Returns:



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

def setup_defaults
  add_help
  @handler = Cliqr::Util.forward_to_help_handler if @handler.nil? && help? && actions?
  @actions.each(&:setup_defaults)
end