Class: Axn::Configurable::NamespaceWriter

Inherits:
Object
  • Object
show all
Defined in:
lib/axn/configurable.rb

Overview

The bag axn_configure/configure yields. Each <setting>= writes into the class's [namespace][setting] override slot, validating first through the namespace's registered source when there is one (else storing tolerantly for a later validate-on-read).

Instance Method Summary collapse

Constructor Details

#initialize(klass, namespace) ⇒ NamespaceWriter

Returns a new instance of NamespaceWriter.



420
421
422
423
# File 'lib/axn/configurable.rb', line 420

def initialize(klass, namespace)
  @klass = klass
  @namespace = namespace
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



429
430
431
432
433
434
435
436
437
438
439
440
# File 'lib/axn/configurable.rb', line 429

def method_missing(name, *args)
  str = name.to_s
  return super unless str.end_with?("=")

  key = str.delete_suffix("=").to_sym
  value = args.first
  _registered_source&._validate_override_setter!(key, value)

  store = @klass.instance_variable_get(:@_axn_config_overrides) ||
          @klass.instance_variable_set(:@_axn_config_overrides, {})
  (store[@namespace] ||= {})[key] = value
end

Instance Method Details

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

Returns:

  • (Boolean)


425
426
427
# File 'lib/axn/configurable.rb', line 425

def respond_to_missing?(name, _include_private = false)
  name.to_s.end_with?("=") || super
end