Class: Crabfarm::TransitionService
- Inherits:
-
Object
- Object
- Crabfarm::TransitionService
- Defined in:
- lib/crabfarm/transition_service.rb
Defined Under Namespace
Classes: DecoratorChain
Instance Attribute Summary collapse
-
#document ⇒ Object
readonly
Returns the value of attribute document.
-
#navigator ⇒ Object
readonly
Returns the value of attribute navigator.
Class Method Summary collapse
- .current_decorator ⇒ Object
- .transition(_context, _name, _params = {}) ⇒ Object
- .with_navigator_decorator(_decorator) ⇒ Object
Instance Method Summary collapse
-
#initialize(_context) ⇒ TransitionService
constructor
A new instance of TransitionService.
- #transition(_name, _params = {}) ⇒ Object
Constructor Details
#initialize(_context) ⇒ TransitionService
Returns a new instance of TransitionService.
23 24 25 |
# File 'lib/crabfarm/transition_service.rb', line 23 def initialize(_context) @context = _context end |
Instance Attribute Details
#document ⇒ Object (readonly)
Returns the value of attribute document.
21 22 23 |
# File 'lib/crabfarm/transition_service.rb', line 21 def document @document end |
#navigator ⇒ Object (readonly)
Returns the value of attribute navigator.
21 22 23 |
# File 'lib/crabfarm/transition_service.rb', line 21 def navigator @navigator end |
Class Method Details
.current_decorator ⇒ Object
13 14 15 |
# File 'lib/crabfarm/transition_service.rb', line 13 def self.current_decorator @decorator end |
.transition(_context, _name, _params = {}) ⇒ Object
17 18 19 |
# File 'lib/crabfarm/transition_service.rb', line 17 def self.transition(_context, _name, _params={}) self.new(_context).transition(_name, _params) end |
.with_navigator_decorator(_decorator) ⇒ Object
4 5 6 7 8 9 10 11 |
# File 'lib/crabfarm/transition_service.rb', line 4 def self.with_navigator_decorator(_decorator) @decorator = DecoratorChain.new @decorator, _decorator begin yield ensure @decorator = @decorator.base end end |
Instance Method Details
#transition(_name, _params = {}) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/crabfarm/transition_service.rb', line 27 def transition(_name, _params={}) navigator_class = if _name.is_a? String or _name.is_a? Symbol load_class_from_uri _name else _name end @context.prepare @navigator = navigator_class.new @context, _params @navigator = current_decorator.decorate @navigator unless current_decorator.nil? @document = @navigator.run @document = @document.as_json if @document.respond_to? :as_json self end |