Class: Skywalker::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/skywalker/command.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**args) ⇒ Command

Instantiates command, setting all arguments.



16
17
18
19
20
21
22
23
24
# File 'lib/skywalker/command.rb', line 16

def initialize(**args)
  args.each_pair do |k, v|
    singleton_class.class_eval do
      send(:attr_accessor, k) unless self.respond_to? k
    end

    self.send("#{k}=", v)
  end
end

Instance Attribute Details

#errorObject

Returns the value of attribute error.



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

def error
  @error
end

#on_failureObject

Returns the value of attribute on_failure.



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

def on_failure
  @on_failure
end

#on_successObject

Returns the value of attribute on_success.



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

def on_success
  @on_success
end

Class Method Details

.call(*args) ⇒ Object

Class interface



8
9
10
# File 'lib/skywalker/command.rb', line 8

def self.call(*args)
  new(*args).call
end

Instance Method Details

#callObject

Call: runs the transaction and all operations.



35
36
37
38
39
40
41
42
43
44
# File 'lib/skywalker/command.rb', line 35

def call
  transaction do
    execute!

    confirm_success
  end

rescue Exception => error
  confirm_failure error
end