Class: SimpleTools::Operation
- Inherits:
-
Object
- Object
- SimpleTools::Operation
- Defined in:
- lib/simple_tools/operation.rb
Class Attribute Summary collapse
-
.steps ⇒ Object
readonly
Returns the value of attribute steps.
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
- #failure? ⇒ Boolean
-
#initialize(params) ⇒ Operation
constructor
A new instance of Operation.
- #success? ⇒ Boolean
Constructor Details
#initialize(params) ⇒ Operation
Returns a new instance of Operation.
23 24 25 26 27 |
# File 'lib/simple_tools/operation.rb', line 23 def initialize(params) @errors = {} @context = {} @params = params end |
Class Attribute Details
.steps ⇒ Object (readonly)
Returns the value of attribute steps.
8 9 10 |
# File 'lib/simple_tools/operation.rb', line 8 def steps @steps end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
5 6 7 |
# File 'lib/simple_tools/operation.rb', line 5 def context @context end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
5 6 7 |
# File 'lib/simple_tools/operation.rb', line 5 def errors @errors end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
5 6 7 |
# File 'lib/simple_tools/operation.rb', line 5 def params @params end |
Class Method Details
.call(params = {}) ⇒ Object
10 11 12 13 14 |
# File 'lib/simple_tools/operation.rb', line 10 def call(params = {}) instance = new(params) instance.call instance end |
.step(key) ⇒ Object
16 17 18 19 20 |
# File 'lib/simple_tools/operation.rb', line 16 def step(key) raise(ArgumentError, 'symbol should be given') unless key.is_a?(Symbol) (@steps ||= []).push(key.to_sym) end |
Instance Method Details
#call ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/simple_tools/operation.rb', line 29 def call raise(ArgumentError, 'steps are not defined') unless self.class.steps self.class.steps.each do |step| public_send(step) break unless success? end end |
#failure? ⇒ Boolean
43 44 45 |
# File 'lib/simple_tools/operation.rb', line 43 def failure? !success? end |
#success? ⇒ Boolean
38 39 40 41 |
# File 'lib/simple_tools/operation.rb', line 38 def success? errors.empty? # force developer to write descriptions of errors end |