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.



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

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

Instance Attribute Details

#runningObject (readonly)

Returns the value of attribute running.



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

def running
  @running
end

Instance Method Details

#add(method_name, *args) ⇒ Object



14
15
16
17
# File 'lib/eye/utils/celluloid_chain.rb', line 14

def add(method_name, *args)
  @calls << { method_name: method_name, args: args }
  ensure_process
end

#add_wo_dups(method_name, *args) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/eye/utils/celluloid_chain.rb', line 19

def add_wo_dups(method_name, *args)
  h = { method_name: method_name, args: args }
  if @calls[-1] != h
    @calls << h
    ensure_process
  end
end

#add_wo_dups_current(method_name, *args) ⇒ Object



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

def add_wo_dups_current(method_name, *args)
  h = { method_name: method_name, args: args }
  if !@calls.include?(h) && @call != h
    @calls << h
    ensure_process
  end
end

#clearObject Also known as: clear_pending_list



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

def clear
  @calls = []
end

#inspectObject



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

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

#listObject



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

def list
  @calls
end

#names_listObject



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

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