Class: Configurate::Settings

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/configurate.rb

Overview

This is your main entry point. Instead of lengthy explanations let an example demonstrate its usage:

require 'configuration_methods'

AppSettings = Configurate::Settings.create do
  add_provider Configurate::Provider::Env
  add_provider Configurate::Provider::YAML, '/etc/app_settings.yml',
               namespace: Rails.env, required: false
  add_provider Configurate::Provider::YAML, 'config/default_settings.yml'

  extend YourConfigurationMethods
end

AppSettings.setup_something if AppSettings.something.enable?

Please also read the note at Proxy!

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSettings

Returns a new instance of Settings.


44
45
46
47
# File 'lib/configurate.rb', line 44

def initialize
  @lookup_chain = LookupChain.new
  warn "Warning you called Configurate::Settings.new with a block, you really meant to call #create" if block_given?
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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

See description and #lookup, #[] and #add_provider


61
62
63
# File 'lib/configurate.rb', line 61

def method_missing(method, *args, &block)
  Proxy.new(@lookup_chain).public_send(method, *args, &block)
end

Instance Attribute Details

#lookup_chainObject (readonly)

Returns the value of attribute lookup_chain


38
39
40
# File 'lib/configurate.rb', line 38

def lookup_chain
  @lookup_chain
end

Class Method Details

.create { ... } ⇒ Object

Create a new configuration object

Yields:

  • the given block will be evaluated in the context of the new object


67
68
69
70
71
# File 'lib/configurate.rb', line 67

def self.create(&block)
  config = new
  config.instance_eval(&block) if block_given?
  config
end

Instance Method Details

#[](setting) ⇒ Object


58
# File 'lib/configurate.rb', line 58

def_delegators :@lookup_chain, :lookup, :add_provider, :[]

#add_provider(provider, *args) ⇒ Object


# File 'lib/configurate.rb', line 52

#lookup(setting) ⇒ Object


# File 'lib/configurate.rb', line 49