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!(value: nil, status: :default, message: nil) ⇒ Object
Fail the Command.
-
#pass!(value: nil, 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
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, ) @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, ) 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 |