class Eye::Utils::CelluloidChain

Attributes

running[R]

Public Class Methods

new(target) click to toggle source
# File lib/eye/utils/celluloid_chain.rb, line 6
def initialize(target)
  @target = target
  @calls = []
  @running = false
  @target_class = @target.class
end

Public Instance Methods

add(method_name, *args, &block) click to toggle source
# File lib/eye/utils/celluloid_chain.rb, line 13
def add(method_name, *args, &block)
  @calls << {:method_name => method_name, :args => args, :block => block}
  ensure_process
end
add_wo_dups(method_name, *args, &block) click to toggle source
# File lib/eye/utils/celluloid_chain.rb, line 18
def add_wo_dups(method_name, *args, &block)
  h = {:method_name => method_name, :args => args, :block => block}
  if @calls[-1] != h
    @calls << h
    ensure_process
  end
end
add_wo_dups_current(method_name, *args, &block) click to toggle source
# File lib/eye/utils/celluloid_chain.rb, line 26
def add_wo_dups_current(method_name, *args, &block)
  h = {:method_name => method_name, :args => args, :block => block}
  if !@calls.include?(h) && @call != h
    @calls << h
    ensure_process
  end
end
clear() click to toggle source
# File lib/eye/utils/celluloid_chain.rb, line 42
def clear
  @calls = []
end
Also aliased as: clear_pending_list
clear_pending_list()
Alias for: clear
inspect() click to toggle source

need, because of github.com/celluloid/celluloid/issues/22

# File lib/eye/utils/celluloid_chain.rb, line 49
def inspect
  "Celluloid::Chain(#{@target_class}: #{@calls.size})"
end
list() click to toggle source
# File lib/eye/utils/celluloid_chain.rb, line 34
def list
  @calls
end
names_list() click to toggle source
# File lib/eye/utils/celluloid_chain.rb, line 38
def names_list
  list.map{|el| el[:method_name].to_sym }
end

Private Instance Methods

ensure_process() click to toggle source
# File lib/eye/utils/celluloid_chain.rb, line 57
def ensure_process
  unless @running
    @running = true
    async.process
  end
end
process() click to toggle source
# File lib/eye/utils/celluloid_chain.rb, line 64
def process
  while @call = @calls.shift
    @running = true
    @target.send(@call[:method_name], *@call[:args], &@call[:block]) if @target.alive?
  end
  @running = false
end