Class: Slayer::Command

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#resultObject

Returns the value of attribute result


3
4
5
# File 'lib/slayer/command.rb', line 3

def result
  @result
end

Class Method Details

.call(*args, &block) ⇒ Object


7
8
9
# File 'lib/slayer/command.rb', line 7

def call(*args, &block)
  execute_call(block, *args) { |c, *a| c.run(*a) }
end

.call!(*args, &block) ⇒ Object


11
12
13
# File 'lib/slayer/command.rb', line 11

def call!(*args, &block)
  execute_call(block, *args) { |c, *a| c.run!(*a) }
end

Instance Method Details

#callObject

Call the command

Raises:

  • (NotImplementedError)

70
71
72
# File 'lib/slayer/command.rb', line 70

def call
  raise NotImplementedError, 'Commands must define method `#call`.'
end

#fail!(result:, status: :default, message: nil) ⇒ Object

Fail the Command


59
60
61
62
# File 'lib/slayer/command.rb', line 59

def fail!(result:, status: :default, message: nil)
  @result = Result.new(result, status, message)
  @result.fail!
end

#pass!(result:, status: :default, message: nil) ⇒ Object

Pass the Command


65
66
67
# File 'lib/slayer/command.rb', line 65

def pass!(result:, status: :default, message: nil)
  @result = Result.new(result, status, message)
end

#run(*args) ⇒ Object

<< self


47
48
49
50
51
# File 'lib/slayer/command.rb', line 47

def run(*args)
  call(*args)
rescue CommandFailureError
  # Swallow the Command Failure
end

#run!(*args) ⇒ Object

Run the Command


54
55
56
# File 'lib/slayer/command.rb', line 54

def run!(*args)
  call(*args)
end