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)


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

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

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

Fail the Command



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

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

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

Pass the Command



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

def pass!(value: nil, status: :default, message: nil)
  @result = Result.new(value, 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