Class: Naught::ChainProxy Private

Inherits:
BasicObject
Defined in:
lib/naught/chain_proxy.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Lightweight proxy for tracking chained method calls

Used by the callstack feature to group chained method calls (e.g., null.foo.bar.baz) into a single trace while keeping separate calls (e.g., null.foo; null.bar) in separate traces.

Instance Method Summary collapse

Constructor Details

#initialize(root, current_trace) ⇒ ChainProxy

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Create a new ChainProxy

Parameters:

  • root (Object)

    the original null object being tracked

  • current_trace (Array<CallLocation>)

    the trace to append calls to



16
17
18
19
# File 'lib/naught/chain_proxy.rb', line 16

def initialize(root, current_trace)
  @root = root
  @current_trace = current_trace
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args) ⇒ ChainProxy

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Handle method calls by recording them and returning self for chaining

rubocop:disable Style/MissingRespondToMissing -- BasicObject doesn't use respond_to_missing?

Parameters:

  • method_name (Symbol)

    the method being called

  • args (Array)

    arguments passed to the method

Returns:



27
28
29
30
31
32
33
# File 'lib/naught/chain_proxy.rb', line 27

def method_missing(method_name, *args)
  location = ::Naught::CallLocation.from_caller(
    method_name, args, ::Kernel.caller(1, 1).first
  )
  @current_trace << location
  self
end

Instance Method Details

#classClass

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return the class of the root null object

Returns:

  • (Class)

    the class of the root null object



49
# File 'lib/naught/chain_proxy.rb', line 49

def class = @root.class

#inspectString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return a string representation of the proxy

Returns:

  • (String)

    a simple representation of the proxy



44
# File 'lib/naught/chain_proxy.rb', line 44

def inspect = "<null:chain>"

#respond_to?true

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Check if the proxy responds to a method

Returns:

  • (true)

    chain proxies respond to any method



39
# File 'lib/naught/chain_proxy.rb', line 39

def respond_to?(*, **) = true