Class: Commands::Command
Direct Known Subclasses
AbstractInstanceGroupCommand, AbstractListCommand, AbstractSSHCommand, BootstrapActionCommand, EipCommand, HelpCommand, SetTerminationProtection, StepCommand, StepProcessingCommand, TerminateActionCommand, VersionCommand
Instance Attribute Summary collapse
-
#arg ⇒ Object
Returns the value of attribute arg.
-
#commands ⇒ Object
Returns the value of attribute commands.
-
#description ⇒ Object
Returns the value of attribute description.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
-
#enact(client) ⇒ Object
action the command.
- #get_field(field_symbol, default_value = nil) ⇒ Object
- #has_value(obj, *args) ⇒ Object
- #have(field_symbol) ⇒ Object
-
#initialize(name, description, arg, commands) ⇒ Command
constructor
A new instance of Command.
- #option(argument_name, argument_symbol, value) ⇒ Object
- #require(field_symbol, error_msg) ⇒ Object
- #require_single_jobflow ⇒ Object
- #resolve(obj, *args) ⇒ Object
-
#validate ⇒ Object
test any constraints that the command has.
Constructor Details
#initialize(name, description, arg, commands) ⇒ Command
Returns a new instance of Command.
101 102 103 104 105 106 107 |
# File 'lib/commands.rb', line 101 def initialize(name, description, arg, commands) @name = name @description = description @arg = arg @commands = commands @logger = commands.logger end |
Instance Attribute Details
#arg ⇒ Object
Returns the value of attribute arg.
99 100 101 |
# File 'lib/commands.rb', line 99 def arg @arg end |
#commands ⇒ Object
Returns the value of attribute commands.
99 100 101 |
# File 'lib/commands.rb', line 99 def commands @commands end |
#description ⇒ Object
Returns the value of attribute description.
99 100 101 |
# File 'lib/commands.rb', line 99 def description @description end |
#logger ⇒ Object
Returns the value of attribute logger.
99 100 101 |
# File 'lib/commands.rb', line 99 def logger @logger end |
#name ⇒ Object
Returns the value of attribute name.
99 100 101 |
# File 'lib/commands.rb', line 99 def name @name end |
Instance Method Details
#enact(client) ⇒ Object
action the command
114 115 |
# File 'lib/commands.rb', line 114 def enact(client) end |
#get_field(field_symbol, default_value = nil) ⇒ Object
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/commands.rb', line 128 def get_field(field_symbol, default_value=nil) value = nil if respond_to?(field_symbol) then value = self.send(field_symbol) end if value == nil then value = @commands.[field_symbol] end default_field_symbol = ("default_" + field_symbol.to_s).to_sym if value == nil && respond_to?(default_field_symbol) then value = self.send(default_field_symbol) end if value == nil then value = default_value end return value end |
#has_value(obj, *args) ⇒ Object
159 160 161 162 163 164 |
# File 'lib/commands.rb', line 159 def has_value(obj, *args) while obj != nil && args.size > 1 do obj = obj[args.shift] end return obj == args[0] end |
#have(field_symbol) ⇒ Object
154 155 156 157 |
# File 'lib/commands.rb', line 154 def have(field_symbol) value = get_field(field_symbol) return value != nil end |
#option(argument_name, argument_symbol, value) ⇒ Object
117 118 119 120 121 122 123 124 125 126 |
# File 'lib/commands.rb', line 117 def option(argument_name, argument_symbol, value) var = self.send(argument_symbol) if var == nil then self.send((argument_symbol.to_s + "=").to_sym, value) elsif var.is_a?(Array) then var << value else raise RuntimeError, "Repeating #{argument_name} is not allowed, previous value was #{var.inspect}" end end |
#require(field_symbol, error_msg) ⇒ Object
146 147 148 149 150 151 152 |
# File 'lib/commands.rb', line 146 def require(field_symbol, error_msg) value = get_field(field_symbol) if value == nil then raise RuntimeError, error_msg end return value end |
#require_single_jobflow ⇒ Object
173 174 175 176 177 178 179 180 181 |
# File 'lib/commands.rb', line 173 def require_single_jobflow jobflow_ids = get_field(:jobflow) if jobflow_ids.size == 0 then raise RuntimeError, "A jobflow is required to use option #{name}" elsif jobflow_ids.size > 1 then raise RuntimeError, "The option #{name} can only act on a single jobflow" end return jobflow_ids.first end |
#resolve(obj, *args) ⇒ Object
166 167 168 169 170 171 |
# File 'lib/commands.rb', line 166 def resolve(obj, *args) while obj != nil && args.size > 0 do obj = obj[args.shift] end return obj end |
#validate ⇒ Object
test any constraints that the command has
110 111 |
# File 'lib/commands.rb', line 110 def validate end |