Class: Yaso::Service
- Inherits:
-
Object
- Object
- Yaso::Service
- Extended by:
- Stepable
- Defined in:
- lib/yaso/service.rb
Instance Attribute Summary collapse
-
#success ⇒ Object
writeonly
Sets the attribute success.
Class Method Summary collapse
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #failure? ⇒ Boolean
-
#initialize(context) ⇒ Service
constructor
A new instance of Service.
- #inspect ⇒ Object
- #success? ⇒ Boolean
- #to_h ⇒ Object
Methods included from Stepable
Constructor Details
#initialize(context) ⇒ Service
Returns a new instance of Service.
9 10 11 12 |
# File 'lib/yaso/service.rb', line 9 def initialize(context) @context = context @success = true end |
Instance Attribute Details
#success=(value) ⇒ Object (writeonly)
Sets the attribute success
7 8 9 |
# File 'lib/yaso/service.rb', line 7 def success=(value) @success = value end |
Class Method Details
.call(context = {}) ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/yaso/service.rb', line 39 def call(context = {}) @entry ||= flow.call(self, steps) step = @entry instance = new(context) step = step.call(context, instance) while step instance end |
Instance Method Details
#[](key) ⇒ Object
14 15 16 |
# File 'lib/yaso/service.rb', line 14 def [](key) @context[key] end |
#[]=(key, value) ⇒ Object
18 19 20 |
# File 'lib/yaso/service.rb', line 18 def []=(key, value) @context[key] = value end |
#failure? ⇒ Boolean
26 27 28 |
# File 'lib/yaso/service.rb', line 26 def failure? !@success end |
#inspect ⇒ Object
34 35 36 |
# File 'lib/yaso/service.rb', line 34 def inspect "Result:#{self.class} successful: #{@success}, context: #{@context}" end |
#success? ⇒ Boolean
22 23 24 |
# File 'lib/yaso/service.rb', line 22 def success? @success end |
#to_h ⇒ Object
30 31 32 |
# File 'lib/yaso/service.rb', line 30 def to_h @context.dup end |