Class: Rguidepost::Command
- Inherits:
-
Object
- Object
- Rguidepost::Command
- Defined in:
- lib/rguidepost/command.rb
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(entire_data, command_key) ⇒ Command
constructor
A new instance of Command.
Constructor Details
#initialize(entire_data, command_key) ⇒ Command
Returns a new instance of Command.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/rguidepost/command.rb', line 3 def initialize(entire_data, command_key) @entire_data = entire_data command_data = @entire_data[command_key] @command_string = command_data if command_data.is_a? String if command_data.is_a? Hash @command_string = command_data["command"] @pre_command = Command.new(@entire_data, command_data["pre_command"]) unless command_data["pre_command"].nil? @ignore_pre = command_data["ignore_pre"] || false @post_command = Command.new(@entire_data, command_data["post_command"]) unless command_data["post_command"].nil? @ensure_post = command_data["ensure_post"] || false end raise "#{command_key}: undefined command." if @command_string.nil? || @command_string == "" end |
Instance Method Details
#execute ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/rguidepost/command.rb', line 19 def execute unless @pre_command.nil? success = @pre_command.execute return false if !success && !@ignore_pre end status = execute_command(@command_string) return status.success? if @post_command.nil? return false if !status.success? && !@ensure_post success = @post_command.execute success end |