Class: Verifly::DependentCallbacks::CallbackGroup::TSortService
- Inherits:
-
Object
- Object
- Verifly::DependentCallbacks::CallbackGroup::TSortService
- Includes:
- TSort
- Defined in:
- lib/verifly/dependent_callbacks/callback_group.rb
Overview
Implements topoplogy sorting of callbacks. As far as CallbackGroup is designed to store Callbacks, it is unable to link them into graph immediately . Service can do it, because if some callbacks are missing on compilation stage, there should be an error
Instance Attribute Summary collapse
-
#dependencies ⇒ { Callback => Callback }
dependency graph.
Class Method Summary collapse
-
.call(callback_group) ⇒ [Callback]
Tsorted callbacks array (aka sequence).
Instance Method Summary collapse
-
#initialize(callback_group) ⇒ TSortService
constructor
A new instance of TSortService.
Constructor Details
#initialize(callback_group) ⇒ TSortService
Returns a new instance of TSortService.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/verifly/dependent_callbacks/callback_group.rb', line 30 def initialize(callback_group) self.dependencies = Hash.new { |h, k| h[k] = Set[] } callback_group.list.each do |callback| dependencies[callback] ||= [] callback.before.each do |key| dependencies[callback_group.index.fetch(key)] << callback end callback.after.each do |key| dependencies[callback] << callback_group.index.fetch(key) end end end |
Instance Attribute Details
Class Method Details
.call(callback_group) ⇒ [Callback]
Returns tsorted callbacks array (aka sequence).
25 26 27 |
# File 'lib/verifly/dependent_callbacks/callback_group.rb', line 25 def self.call(callback_group) new(callback_group).tsort end |