Class: Yarrow::Configuration

Inherits:
Hashie::Mash
  • Object
show all
Defined in:
lib/yarrow/configuration.rb

Overview

Hash-like object containing runtime configuration values. Can be accessed indifferently via object style lookups or symbol keys.

Class Method Summary collapse

Class Method Details

.clearObject

Clears the global configuration to the empty default.



43
44
45
# File 'lib/yarrow/configuration.rb', line 43

def clear
  @@configuration = self.new
end

.instanceYarrow::Configuration

Provides access to the registered global configuration.

If no configuration is registered, returns a blank object.



15
16
17
# File 'lib/yarrow/configuration.rb', line 15

def instance
  @@configuration ||= self.new
end

.load(file) ⇒ Yarrow::Configuration

Loads a configuration object from the given YAML file.

Parameters:

  • path (String)

    to YAML file

Returns:



64
65
66
# File 'lib/yarrow/configuration.rb', line 64

def load(file)
  self.new(YAML.load_file(file))
end

.load_defaultsYarrow::Configuration

Yarrow is distributed with a ‘defaults.yml` which provides minimum boostrap configuration and default settings for various internal classes. Use this method to automatically load these defaults.



74
75
76
# File 'lib/yarrow/configuration.rb', line 74

def load_defaults
  load(File.join(File.dirname(__FILE__), 'defaults.yml'))
end

.merge(config) ⇒ Object

Merges the given configuration or hash-like object with the registered global configuration.

Parameters:



53
54
55
# File 'lib/yarrow/configuration.rb', line 53

def merge(config)
  instance.deep_merge!(config)
end

.register(file) ⇒ Object

Loads and registers a global configuration instance.

This will reset any previously initialized configuration.

Parameters:

  • path (String)

    to YAML file



26
27
28
# File 'lib/yarrow/configuration.rb', line 26

def register(file)
  @@configuration = load(file)
end

.register_defaultsObject

Loads and registers a global configuration instance with library-provided defaults.

This will reset any previously initialized configuration.



36
37
38
# File 'lib/yarrow/configuration.rb', line 36

def register_defaults
  @@configuration = load_defaults
end