Class: Tasker::Configuration::ConfigurationProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/tasker/configuration.rb

Overview

Simple proxy object for configuration blocks that provides dot-notation access to hash values without the overhead of OpenStruct.

This enables clean configuration syntax like: config.auth do |auth| auth.authentication_enabled = true auth.authenticator_class = 'MyAuth' end

While maintaining the benefits of dry-struct validation and immutability.

Direct Known Subclasses

TelemetryConfigurationProxy

Instance Method Summary collapse

Constructor Details

#initialize(hash = {}) ⇒ ConfigurationProxy

Initialize a new configuration proxy with hash data

Parameters:

  • hash (Hash) (defaults to: {})

    The hash data to wrap



26
27
28
# File 'lib/tasker/configuration.rb', line 26

def initialize(hash = {})
  @hash = hash.transform_keys(&:to_sym)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args) ⇒ Object

Handle dynamic method calls for configuration access

Parameters:

  • method_name (Symbol)

    The method being called

  • args (Array)

    Arguments passed to the method



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/tasker/configuration.rb', line 34

def method_missing(method_name, *args)
  if method_name.to_s.end_with?('=')
    # Setter: config.authentication_enabled = true
    key = method_name.to_s.chomp('=').to_sym
    @hash[key] = args.first
  elsif @hash.key?(method_name.to_sym)
    # Getter: config.authentication_enabled
    @hash[method_name.to_sym]
  else
    super
  end
end

Instance Method Details

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

Check if the proxy responds to a given method

Parameters:

  • method_name (Symbol)

    The method name to check

  • include_private (Boolean) (defaults to: false)

    Whether to include private methods

Returns:

  • (Boolean)

    True if the method is supported



52
53
54
# File 'lib/tasker/configuration.rb', line 52

def respond_to_missing?(method_name, include_private = false)
  method_name.to_s.end_with?('=') || @hash.key?(method_name.to_sym) || super
end

#to_hHash

Convert the proxy back to a hash for dry-struct creation

Returns:

  • (Hash)

    The underlying hash data



59
60
61
# File 'lib/tasker/configuration.rb', line 59

def to_h
  @hash
end