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
11
# File 'lib/eye/utils/celluloid_chain.rb', line 6

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

Instance Attribute Details

#runningObject (readonly)

Returns the value of attribute running


53
54
55
# File 'lib/eye/utils/celluloid_chain.rb', line 53

def running
  @running
end

Instance Method Details

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


13
14
15
16
# 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) ⇒ Object


18
19
20
21
22
23
24
# 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) ⇒ Object


26
27
28
29
30
31
32
# 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

#clearObject Also known as: clear_pending_list


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

def clear
  @calls = []
end

#inspectObject


49
50
51
# File 'lib/eye/utils/celluloid_chain.rb', line 49

def inspect
  "Celluloid::Chain(#{@target_class}: #{@calls.size})"
end

#listObject


34
35
36
# File 'lib/eye/utils/celluloid_chain.rb', line 34

def list
  @calls
end

#names_listObject


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

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