Class: Fibril::FibrilProxy

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

Constant Summary collapse

ENUM_METHODS =
%w(map each each_with_index with_index with_object detect select each_slice each_cons each_entry reverse_each)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target, *guard_names) ⇒ FibrilProxy

Returns a new instance of FibrilProxy.



6
7
8
9
# File 'lib/fibril/fibril_proxy.rb', line 6

def initialize(target, *guard_names)
  self.target = target
  self.guard_names = guard_names
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



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

def method_missing(name, *args, &block)

  context = target

  return context.send(name).fibril(*self.guard_names) do |*elms, &blk|
    block[*elms, &blk]
  end if ENUM_METHODS.include?(name.to_s)


  fibril{
    context.send(name, *args, &block)
  }.tap do |guard|
    guard_names.each do |guard_name|
      Fibril.guard.send("#{guard_name}=", guard)
    end
  end
end

Instance Attribute Details

#guard_namesObject

Returns the value of attribute guard_names.



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

def guard_names
  @guard_names
end

#targetObject

Returns the value of attribute target.



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

def target
  @target
end