Class: Dry::System::Components::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/dry/system/components/config.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



13
14
15
# File 'lib/dry/system/components/config.rb', line 13

def initialize
  @settings = {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, value = nil) ⇒ Object (private)



23
24
25
26
27
28
29
30
31
# File 'lib/dry/system/components/config.rb', line 23

def method_missing(meth, value = nil)
  if meth.to_s.end_with?('=')
    @settings[meth.to_s.gsub('=', '').to_sym] = value
  elsif @settings.key?(meth)
    @settings[meth]
  else
    super
  end
end

Class Method Details

.new {|config| ... } ⇒ Object

Yields:

  • (config)


7
8
9
10
11
# File 'lib/dry/system/components/config.rb', line 7

def self.new(&block)
  config = super
  yield(config) if block_given?
  config
end

Instance Method Details

#to_hashObject



17
18
19
# File 'lib/dry/system/components/config.rb', line 17

def to_hash
  @settings
end