Class: EvilEvents::Shared::AnyConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/evil_events/shared/any_config.rb

Overview

Since:

  • 0.4.0

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAnyConfig

Returns a new instance of AnyConfig.

Since:

  • 0.4.0



26
27
28
29
30
31
32
33
34
35
# File 'lib/evil_events/shared/any_config.rb', line 26

def initialize
  setup = self.class.configure

  @config = Module.new do
    extend Dry::Configurable
    instance_eval(&setup)
  end

  @config.configure { |conf| yield(conf) if block_given? }
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *attributes, &block) ⇒ Object

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.

Since:

  • 0.4.0



48
49
50
51
# File 'lib/evil_events/shared/any_config.rb', line 48

def method_missing(method_name, *attributes, &block)
  return super unless @config.respond_to?(method_name)
  @config.public_send(method_name, *attributes, &block)
end

Class Method Details

.configure(&configuration) ⇒ Proc

Parameters:

  • configuration (Proc)

Returns:

  • (Proc)

Since:

  • 0.4.0



12
13
14
15
16
17
18
19
20
21
# File 'lib/evil_events/shared/any_config.rb', line 12

def configure(&configuration)
  case
  when !block_given? && !instance_variable_defined?(:@setup)
    @setup = proc {}
  when block_given?
    @setup = configuration
  else
    @setup
  end
end

Instance Method Details

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

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.

:nocov:

Returns:

  • (Boolean)

Since:

  • 0.4.0



56
57
58
# File 'lib/evil_events/shared/any_config.rb', line 56

def respond_to_missing?(method_name, include_private = false)
  @config.respond_to?(method_name, include_private) || super
end

#to_hHash Also known as: to_hash

Returns:

  • (Hash)

Since:

  • 0.4.0



41
42
43
# File 'lib/evil_events/shared/any_config.rb', line 41

def to_h
  @config.config.to_h
end