Class: Slayer::Command
- Inherits:
-
Object
- Object
- Slayer::Command
- Defined in:
- lib/slayer/command.rb
Instance Attribute Summary collapse
-
#result ⇒ Object
Returns the value of attribute result.
Class Method Summary collapse
Instance Method Summary collapse
-
#call ⇒ Object
Call the command.
-
#fail!(result:, status: :default, message: nil) ⇒ Object
Fail the Command.
-
#pass!(result:, status: :default, message: nil) ⇒ Object
Pass the Command.
-
#run(*args) ⇒ Object
<< self.
-
#run!(*args) ⇒ Object
Run the Command.
Instance Attribute Details
#result ⇒ Object
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
#call ⇒ Object
Call the command
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, ) @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, ) 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 |