Class: Hyperion::Config::BlockProxy

Inherits:
BasicObject
Defined in:
lib/hyperion/config.rb

Overview

Block-form DSL proxy for nested subconfigs. Each bareword call inside ‘h2 do; max_concurrent_streams 256; end` lands on this proxy, which forwards into the wrapped subconfig’s setter. Also supports explicit-arg form ‘h2 do |h| h.max_concurrent_streams 256 end` via the same accessor path. Unknown method names raise NoMethodError — typos surface at boot, matching the top-level DSL’s strictness.

Inherits from BasicObject so Ruby’s ‘Kernel#format` / `Kernel#level` / etc. don’t shadow our subconfig setters when callers write ‘logging do; format :json; end` — Kernel methods are absent on BasicObject, so the bareword falls through to method_missing.

Instance Method Summary collapse

Constructor Details

#initialize(target) ⇒ BlockProxy

Returns a new instance of BlockProxy.



508
509
510
# File 'lib/hyperion/config.rb', line 508

def initialize(target)
  @target = target
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
# File 'lib/hyperion/config.rb', line 512

def method_missing(name, *args, &block)
  setter = :"#{name}="
  if @target.respond_to?(setter)
    # Single-arg sets (`max_concurrent_streams 256`) write the
    # value through. Zero-arg calls (`max_concurrent_streams`)
    # behave as readers — needed by the explicit-arg form so
    # `h.max_concurrent_streams` returns the current value.
    if args.length == 1
      @target.public_send(setter, args.first)
    elsif args.empty? && @target.respond_to?(name)
      @target.public_send(name)
    else
      ::Kernel.raise ::NoMethodError, "no DSL setter for #{name.inspect} on #{@target.class}"
    end
  elsif @target.respond_to?(name)
    @target.public_send(name, *args, &block)
  else
    ::Kernel.raise ::NoMethodError, "no DSL setter for #{name.inspect} on #{@target.class}"
  end
end

Instance Method Details

#classObject

BasicObject lacks #class — provide it for tests + introspection.



539
540
541
# File 'lib/hyperion/config.rb', line 539

def class
  ::Hyperion::Config::BlockProxy
end

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

Returns:

  • (Boolean)


533
534
535
536
# File 'lib/hyperion/config.rb', line 533

def respond_to_missing?(name, include_private = false)
  setter = :"#{name}="
  @target.respond_to?(setter) || @target.respond_to?(name, include_private)
end