Class: EvilEvents::Shared::AnyConfig
- Inherits:
-
Object
- Object
- EvilEvents::Shared::AnyConfig
- Defined in:
- lib/evil_events/shared/any_config.rb
Overview
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ AnyConfig
constructor
A new instance of AnyConfig.
- #method_missing(method_name, *attributes, &block) ⇒ Object private
-
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
private
:nocov:.
- #to_h ⇒ Hash (also: #to_hash)
Constructor Details
#initialize ⇒ AnyConfig
Returns a new instance of AnyConfig.
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.
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
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:
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_h ⇒ Hash Also known as: to_hash
41 42 43 |
# File 'lib/evil_events/shared/any_config.rb', line 41 def to_h @config.config.to_h end |