Class: ComposedCommands::Command

Inherits:
Object
  • Object
show all
Extended by:
ActiveSupport::Autoload
Defined in:
lib/composed_commands/command.rb,
lib/composed_commands/command/state.rb,
lib/composed_commands/command/execution.rb

Direct Known Subclasses

ComposedCommand

Defined Under Namespace

Classes: Execution, State

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Command

Returns a new instance of Command.



19
20
21
22
23
24
# File 'lib/composed_commands/command.rb', line 19

def initialize(options = {})
  @execution = Execution.new
  @state = State.new

  super(options)
end

Instance Attribute Details

#executionObject

Returns the value of attribute execution.



15
16
17
# File 'lib/composed_commands/command.rb', line 15

def execution
  @execution
end

#messageObject (readonly)

Returns the value of attribute message.



14
15
16
# File 'lib/composed_commands/command.rb', line 14

def message
  @message
end

#resultObject (readonly)

Returns the value of attribute result.



13
14
15
# File 'lib/composed_commands/command.rb', line 13

def result
  @result
end

#stateObject

Returns the value of attribute state.



16
17
18
# File 'lib/composed_commands/command.rb', line 16

def state
  @state
end

Class Method Details

.perform(*args) ⇒ Object



26
27
28
29
# File 'lib/composed_commands/command.rb', line 26

def self.perform(*args)
  options = args.extract_options!
  new(options).perform(*args)
end

Instance Method Details

#halted?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/composed_commands/command.rb', line 42

def halted?
  execution.interrupted?
end

#perform(*args) ⇒ Object



31
32
33
34
35
36
37
38
39
40
# 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