class Verifly::DependentCallbacks::CallbackGroup

Handles callbacks with same 'group' option, allowing to do sequential invokation of them @attr name [Symbol] name of callback group @attr index [{Symbol => Callback}] index for named callback lookup @attr list [[Callback]] all callbacks

Attributes

index[RW]
list[RW]
name[RW]

Public Class Methods

new(name) { |self| ... } click to toggle source

@param name [Symbol] name of callback group @yield self if block given

# File lib/verifly/dependent_callbacks/callback_group.rb, line 65
def initialize(name)
  self.name = name
  self.index = {}
  self.list = []

  yield(self) if block_given?
end

Public Instance Methods

add_callback(callback) click to toggle source

Adds callback to list and index, reset sequence @param callback [Callback] new callback

# File lib/verifly/dependent_callbacks/callback_group.rb, line 75
def add_callback(callback)
  list << callback
  index[callback.name] = callback if callback.name

  @sequence = nil
end
digest() click to toggle source

Digest change forces recompilation of callback group in service @return [Numeric]

# File lib/verifly/dependent_callbacks/callback_group.rb, line 101
def digest
  [name, list].hash
end
merge(other) click to toggle source

Merges with another group @param other [CallbackGroup] @raise if group names differ

# File lib/verifly/dependent_callbacks/callback_group.rb, line 85
def merge(other)
  raise "Only groups with one name could be merged" unless name == other.name

  [*list, *other.list].each_with_object(CallbackGroup.new(name)) do |callback, group|
    group.add_callback(callback)
  end
end
sequence() click to toggle source

Memoizes tsorted graph @return [[Callback]]

# File lib/verifly/dependent_callbacks/callback_group.rb, line 95
def sequence
  @sequence ||= TSortService.call(self)
end
to_dot(binding_) click to toggle source

Renders graphviz dot-representation of callback group @return graphviz dot

# File lib/verifly/dependent_callbacks/callback_group.rb, line 107
def to_dot(binding_)
  template_path = File.expand_path("callback_group.dot.erb", __dir__)
  erb = ERB.new(File.read(template_path))
  erb.filename = template_path
  erb.result(binding)
end