Class: Eye::Utils::CelluloidChain

Inherits:
Object
  • Object
show all
Includes:
Celluloid
Defined in:
lib/eye/utils/celluloid_chain.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target) ⇒ CelluloidChain

Returns a new instance of CelluloidChain.



6
7
8
9
10
# File 'lib/eye/utils/celluloid_chain.rb', line 6

def initialize(target)
  @target = target
  @calls = []
  @running = false
end

Instance Attribute Details

#runningObject (readonly)

Returns the value of attribute running.



42
43
44
# File 'lib/eye/utils/celluloid_chain.rb', line 42

def running
  @running
end

Instance Method Details

#add(method_name, *args, &block) ⇒ Object



12
13
14
15
# File 'lib/eye/utils/celluloid_chain.rb', line 12

def add(method_name, *args, &block)
  @calls << {:method_name => method_name, :args => args, :block => block}
  async.process unless @running
end

#add_wo_dups(method_name, *args, &block) ⇒ Object



17
18
19
20
21
# File 'lib/eye/utils/celluloid_chain.rb', line 17

def add_wo_dups(method_name, *args, &block)
  h = {:method_name => method_name, :args => args, :block => block}
  @calls << h if @calls[-1] != h
  async.process unless @running
end

#clearObject Also known as: clear_pending_list



31
32
33
# File 'lib/eye/utils/celluloid_chain.rb', line 31

def clear
  @calls = []
end

#inspectObject



38
39
40
# File 'lib/eye/utils/celluloid_chain.rb', line 38

def inspect
  "Celluloid::Chain(#{@target.class}: #{@calls.inspect})"
end

#listObject



23
24
25
# File 'lib/eye/utils/celluloid_chain.rb', line 23

def list
  @calls
end

#names_listObject



27
28
29
# File 'lib/eye/utils/celluloid_chain.rb', line 27

def names_list
  list.map{|el| el[:method_name].to_sym }
end