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.



46
47
48
49
# File 'lib/configurate.rb', line 46

def initialize
  @lookup_chain = LookupChain.new
  $stderr.puts "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



63
64
65
# File 'lib/configurate.rb', line 63

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.



40
41
42
# File 'lib/configurate.rb', line 40

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



69
70
71
72
73
# File 'lib/configurate.rb', line 69

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

Instance Method Details

#[](setting) ⇒ Object



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

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

#add_provider(provider, *args) ⇒ Object



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

#lookup(setting) ⇒ Object



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