Class: ProxyRb::ConfigurationWrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/proxy_rb/configuration_wrapper.rb

Overview

This wraps the current runtime configuration of proxy_rb. If an option is changed, it notifies the event queue.

This class is not meant for direct use - ConfigWrapper.new - by normal users.

Instance Method Summary collapse

Constructor Details

#initialize(config, event_bus) ⇒ ConfigurationWrapper

Create proxy

Parameters:

  • config (Config)

    An proxy_rb config object.

  • event_bus (#notify)

    The event queue which should be notified.



24
25
26
27
# File 'lib/proxy_rb/configuration_wrapper.rb', line 24

def initialize(config, event_bus)
  @config = config
  @event_bus = event_bus
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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

Proxy all methods

If one method ends with “=”, e.g. “:option1=”, then notify the event queue, that the user changes the value of “option1”



33
34
35
36
37
# File 'lib/proxy_rb/configuration_wrapper.rb', line 33

def method_missing(name, *args, &block)
  event_bus.notify Events::ChangedConfiguration.new(changed: { name: name.to_s.gsub(/=$/, ''), value: args.first }) if name.to_s.end_with? '='

  config.send(name, *args, &block)
end

Instance Method Details

#==(other) ⇒ Object

Compare two configs

The comparism is done based on their values. No hooks are compared.

Somehow ‘#respond_to_missing?`, `method_missing?` and `respond_to?` don’t help here.



50
51
52
# File 'lib/proxy_rb/configuration_wrapper.rb', line 50

def ==(other)
  config == other
end

#respond_to?(m) ⇒ Boolean

Pass on respond_to?-calls

Returns:

  • (Boolean)


55
56
57
# File 'lib/proxy_rb/configuration_wrapper.rb', line 55

def respond_to?(m)
  config.respond_to? m
end

#respond_to_missing?(name, _include_private) ⇒ Boolean

Pass on respond_to?-calls

Returns:

  • (Boolean)


40
41
42
# File 'lib/proxy_rb/configuration_wrapper.rb', line 40

def respond_to_missing?(name, _include_private)
  config.respond_to? name
end