Class: Taski::TaskProxy

Inherits:
BasicObject
Defined in:
lib/taski/task_proxy.rb

Overview

Lazy proxy that defers dependency resolution until the value is actually used. Inherits from BasicObject to minimize available methods, maximizing method_missing delegation.

Instance Method Summary collapse

Constructor Details

#initialize(task_class, method) ⇒ TaskProxy

Returns a new instance of TaskProxy.



7
8
9
10
11
12
13
# File 'lib/taski/task_proxy.rb', line 7

def initialize(task_class, method)
  @task_class = task_class
  @method = method
  @resolved = false
  @value = nil
  @error = nil
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



31
32
33
# File 'lib/taski/task_proxy.rb', line 31

def method_missing(name, *args, **kwargs, &block)
  __resolve__.__send__(name, *args, **kwargs, &block)
end

Instance Method Details

#!Object



39
40
41
# File 'lib/taski/task_proxy.rb', line 39

def !
  !__resolve__
end

#!=(other) ⇒ Object



47
48
49
# File 'lib/taski/task_proxy.rb', line 47

def !=(other)
  __resolve__ != other
end

#==(other) ⇒ Object



43
44
45
# File 'lib/taski/task_proxy.rb', line 43

def ==(other)
  __resolve__ == other
end

#__resolve__Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/taski/task_proxy.rb', line 15

def __resolve__
  ::Kernel.raise @error if @error
  return @value if @resolved
  @value = ::Fiber.yield(::Taski::Execution::FiberProtocol::NeedDep.new(@task_class, @method))
  if @value in ::Taski::Execution::FiberProtocol::DepError
    @error = @value.error
    ::Kernel.raise @error
  end
  @resolved = true
  @value
end

#__taski_proxy_resolve__Object



27
28
29
# File 'lib/taski/task_proxy.rb', line 27

def __taski_proxy_resolve__
  __resolve__
end

#equal?(other) ⇒ Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/taski/task_proxy.rb', line 51

def equal?(other)
  __resolve__.equal?(other)
end

#respond_to?(name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/taski/task_proxy.rb', line 55

def respond_to?(name, include_private = false)
  name == :__taski_proxy_resolve__ || __resolve__.respond_to?(name, include_private)
end

#respond_to_missing?(name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/taski/task_proxy.rb', line 35

def respond_to_missing?(name, include_private = false)
  name == :__taski_proxy_resolve__ || __resolve__.respond_to?(name, include_private)
end