Class: Fibril::TickProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/fibril/tick_proxy.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target, *guard_names, tick_before: true, tick_after: false) ⇒ TickProxy

Returns a new instance of TickProxy.



4
5
6
7
8
# File 'lib/fibril/tick_proxy.rb', line 4

def initialize(target, *guard_names, tick_before: true, tick_after: false)
  self.target = target
  self.guard_names = guard_names
  self.tick_before, self.tick_after = tick_before, tick_after
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object

Execute target method within a new fibril



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/fibril/tick_proxy.rb', line 13

def method_missing(name, *args, &block)
  context = target
  decorated = ->(*args){
    Fibril.current.tick if tick_before
    result = block[*args]
    Fibril.current.tick if tick_after
    result
  }
  fibril{
    context.send(name, *args, &decorated)
  }.tap do |guard|
    guard_names.each do |name|
      Fibril.guard.send("#{name}=", guard)
    end
  end

end

Instance Attribute Details

#guard_namesObject

Returns the value of attribute guard_names.



2
3
4
# File 'lib/fibril/tick_proxy.rb', line 2

def guard_names
  @guard_names
end

#targetObject

Returns the value of attribute target.



2
3
4
# File 'lib/fibril/tick_proxy.rb', line 2

def target
  @target
end

#tick_afterObject

Returns the value of attribute tick_after.



2
3
4
# File 'lib/fibril/tick_proxy.rb', line 2

def tick_after
  @tick_after
end

#tick_beforeObject

Returns the value of attribute tick_before.



2
3
4
# File 'lib/fibril/tick_proxy.rb', line 2

def tick_before
  @tick_before
end