Class: Tardvig::Command Abstract
- Inherits:
-
Object
- Object
- Tardvig::Command
- Defined in:
- lib/tardvig/command.rb
Overview
The class represents abstract algorithm. It is something like Proc, but your code is stored in the class instead of object so you can use instance variables and divide your code into methods.
See the ‘spec` directory for example.
Direct Known Subclasses
Class Method Summary collapse
-
.call(params = {}) ⇒ Object
Creates a new instance and executes it.
Instance Method Summary collapse
-
#call(params = {}) ⇒ Command
Executes your process (you should redefine the ‘process` method).
-
#execute ⇒ Object
The method is used for be redefined in the situation when you need to change the execution order.
-
#initialize(params = {}) ⇒ Command
constructor
A new instance of Command.
- #process ⇒ Object abstract
Constructor Details
#initialize(params = {}) ⇒ Command
Returns a new instance of Command.
11 12 13 |
# File 'lib/tardvig/command.rb', line 11 def initialize(params = {}) handle_params(params) end |
Class Method Details
.call(params = {}) ⇒ Object
Creates a new instance and executes it.
27 28 29 |
# File 'lib/tardvig/command.rb', line 27 def self.call(params = {}) new.call(params) end |
Instance Method Details
#call(params = {}) ⇒ Command
Executes your process (you should redefine the ‘process` method)
18 19 20 21 22 |
# File 'lib/tardvig/command.rb', line 18 def call(params = {}) handle_params(params) execute self end |
#execute ⇒ Object
The method is used for be redefined in the situation when you need to change the execution order. By default it executes ‘process` only. See the specs for example.
37 38 39 |
# File 'lib/tardvig/command.rb', line 37 def execute process end |
#process ⇒ Object
Redefine this method and it will do whatever you want whilst execution
44 45 46 |
# File 'lib/tardvig/command.rb', line 44 def process raise NoMethodError, 'You should define #process for your Command' end |