class ComposedCommands::Command
Attributes
execution[RW]
message[R]
result[R]
state[RW]
Public Class Methods
new(options = {})
click to toggle source
Calls superclass method
# File lib/composed_commands/command.rb, line 19 def initialize(options = {}) @execution = Execution.new @state = State.new super(options) end
perform(*args)
click to toggle source
# File lib/composed_commands/command.rb, line 26 def self.perform(*args) options = args.extract_options! new(options).perform(*args) end
Public Instance Methods
halted?()
click to toggle source
# File lib/composed_commands/command.rb, line 42 def halted? execution.interrupted? end
perform(*args)
click to toggle source
# File lib/composed_commands/command.rb, line 31 def perform(*args) @result = catch(:halt) do execution.perform! result = execute(*args) state.success! execution.done! result end self end
Protected Instance Methods
execute(*_)
click to toggle source
# File lib/composed_commands/command.rb, line 48 def execute(*_) raise NotImplementedError, "#{self.class.name}#execute not implemented" end
fail!(message)
click to toggle source
# File lib/composed_commands/command.rb, line 52 def fail!(message) # TODO: Move message to result? @message = message state.fail! execution.interrupt! throw :halt end
success!(result)
click to toggle source
# File lib/composed_commands/command.rb, line 60 def success!(result) state.success! execution.interrupt! throw :halt, result end