Class: Cliqr::Config::Action Private
- Inherits:
-
OptionBased
- Object
- Base
- EventBased
- Named
- OptionBased
- Cliqr::Config::Action
- 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
Instance Attribute Summary collapse
-
#actions ⇒ Array<Cliqr::CLI::Config>
private
Array of children action configs for this action.
-
#arguments ⇒ Symbol
private
Dictates whether this command can take arbitrary arguments (optional).
-
#handler ⇒ Class<Cliqr::Command::BaseCommand>
private
Command handler for the base command.
-
#help ⇒ Symbol
private
Enable or disable help command and option.
-
#parent ⇒ Cliqr::Config::CommandConfig
private
Parent configuration.
Attributes inherited from OptionBased
Attributes inherited from Named
Attributes inherited from EventBased
Instance Method Summary collapse
-
#action(name) ⇒ Cliqr::Config::Action
private
Get action config by name.
-
#action?(name) ⇒ Boolean
private
Check if particular action exists.
-
#actions? ⇒ Boolean
private
Check if this config has sub actions.
-
#arguments? ⇒ Boolean
private
Check if arguments are enabled for this configuration.
-
#command ⇒ String
private
Get name of the command along with the action upto this config.
-
#finalize ⇒ Cliqr::Config::Action
private
Finalize config by adding default values for unset values.
-
#help? ⇒ Boolean
private
Check if help is enabled for this command.
-
#initialize ⇒ Action
constructor
private
New config instance with all attributes set as UNSET.
-
#parent? ⇒ Boolean
private
Check if this config has a parent config.
-
#root ⇒ Cliqr::Config::Action
private
The root of action config is itself unless otherwise configured.
-
#root? ⇒ Boolean
private
Check if this action is the root.
-
#set_config(name, value, *args, &block) ⇒ Object, Cliqr::Config::Base
private
Set value for a config option.
-
#setup_defaults ⇒ Cliqr::Config::Command
private
Set up default attributes for this configuration.
Methods inherited from OptionBased
Methods inherited from Named
Methods inherited from EventBased
Methods inherited from Base
Methods included from Validation
#errors, included, #read_attributes, #valid?, #validate, #validations
Methods included from DSL
Constructor Details
#initialize ⇒ 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.
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
#actions ⇒ Array<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
34 35 36 |
# File 'lib/cliqr/config/action.rb', line 34 def actions @actions end |
#arguments ⇒ Symbol
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)
27 28 29 |
# File 'lib/cliqr/config/action.rb', line 27 def arguments @arguments end |
#handler ⇒ Class<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
17 18 19 |
# File 'lib/cliqr/config/action.rb', line 17 def handler @handler end |
#help ⇒ Symbol
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
41 42 43 |
# File 'lib/cliqr/config/action.rb', line 41 def help @help end |
#parent ⇒ Cliqr::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
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
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
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
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
130 131 132 |
# File 'lib/cliqr/config/action.rb', line 130 def arguments? @arguments == ENABLE_CONFIG end |
#command ⇒ 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 name of the command along with the action upto this config
137 138 139 140 |
# File 'lib/cliqr/config/action.rb', line 137 def command return name unless parent? "#{@parent.command} #{name}" end |
#finalize ⇒ 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.
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
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
145 146 147 |
# File 'lib/cliqr/config/action.rb', line 145 def parent? !@parent.nil? end |
#root ⇒ 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.
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
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
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_defaults ⇒ Cliqr::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
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 |