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.



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

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}
  ensure_process
end

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



17
18
19
20
21
22
23
# 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}
  if @calls[-1] != h
    @calls << h
    ensure_process
  end
end

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



25
26
27
28
29
30
31
# File 'lib/eye/utils/celluloid_chain.rb', line 25

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



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

def clear
  @calls = []
end

#inspectObject



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

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

#listObject



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

def list
  @calls
end

#names_listObject



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

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