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.
7 8 9 10 |
# File 'lib/yaso/service.rb', line 7 def initialize(context) @context = context @success = true end |
Instance Attribute Details
#success=(value) ⇒ Object (writeonly)
Sets the attribute success
5 6 7 |
# File 'lib/yaso/service.rb', line 5 def success=(value) @success = value end |
Class Method Details
.call(context = {}) ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/yaso/service.rb', line 37 def call(context = {}) @entry ||= flow.call(self, steps) step = @entry instance = new(context) step = step.call(context, instance) while step instance end |
.flow(name = nil) ⇒ Object
45 46 47 48 49 50 |
# File 'lib/yaso/service.rb', line 45 def flow(name = nil) @flow ||= Flows::MAP[:classic] if self == Yaso::Service return @flow || Yaso::Service.flow if name.nil? @flow = Flows::MAP[name] || raise(UnknownFlowError.new(self, name)) end |
Instance Method Details
#[](key) ⇒ Object
12 13 14 |
# File 'lib/yaso/service.rb', line 12 def [](key) @context[key] end |
#[]=(key, value) ⇒ Object
16 17 18 |
# File 'lib/yaso/service.rb', line 16 def []=(key, value) @context[key] = value end |
#failure? ⇒ Boolean
24 25 26 |
# File 'lib/yaso/service.rb', line 24 def failure? !@success end |
#inspect ⇒ Object
32 33 34 |
# File 'lib/yaso/service.rb', line 32 def inspect "Result:#{self.class} successful: #{@success}, context: #{@context}" end |
#success? ⇒ Boolean
20 21 22 |
# File 'lib/yaso/service.rb', line 20 def success? @success end |
#to_h ⇒ Object
28 29 30 |
# File 'lib/yaso/service.rb', line 28 def to_h @context.dup end |