Class: Immoscout::Configuration

Inherits:
ActiveSupport::OrderedOptions
  • Object
show all
Defined in:
lib/immoscout/configuration.rb

Overview

The configuration object of the immoscout gem.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**args) ⇒ Configuration

Create a new Configuration instance with all settings populated with their respective defaults.

Parameters:

  • args (Hash{Symbol => Mixed})

    additional settings which overwrite the defaults



20
21
22
23
24
# File 'lib/immoscout/configuration.rb', line 20

def initialize(**args)
  super()
  defaults.each { |key, default| self[key] = instance_exec(&default) }
  merge!(**args)
end

Class Method Details

.config_accessor(name, default = nil, &block) ⇒ Object

A simple DSL method to define new configuration accessors/settings with their defaults. The defaults can be retrieved with Configuration.defaults or Configuration.new.defaults.

Parameters:

  • name (Symbol, String)

    the name of the configuration accessor/setting

  • default (Mixed, nil) (defaults to: nil)

    a non-lazy-loaded static value, serving as a default value for the setting

  • block (Proc)

    when given, the default value will be lazy-loaded (result of the Proc)



36
37
38
39
40
41
42
43
44
# File 'lib/immoscout/configuration.rb', line 36

def self.config_accessor(name, default = nil, &block)
  # Save the given configuration accessor default value
  defaults[name.to_sym] = block || -> { default }

  # Compile reader/writer methods so we don't have to go through
  # +ActiveSupport::OrderedOptions#method_missing+.
  define_method(name) { self[name] }
  define_method("#{name}=") { |value| self[name] = value }
end