Module: Elasticonf
- Defined in:
- lib/elasticonf.rb,
lib/elasticonf/config.rb,
lib/elasticonf/loader.rb,
lib/elasticonf/version.rb
Defined Under Namespace
Constant Summary collapse
- VERSION =
'1.1.5'
Class Method Summary collapse
- .config ⇒ Object
- .configure {|config| ... } ⇒ Object
- .configure_and_load! ⇒ Object
- .load!(env = nil) ⇒ Object
- .reload! ⇒ Object
- .root ⇒ Object
Class Method Details
.config ⇒ Object
15 16 17 |
# File 'lib/elasticonf.rb', line 15 def config @config ||= Config.new end |
.configure {|config| ... } ⇒ Object
19 20 21 |
# File 'lib/elasticonf.rb', line 19 def configure yield config end |
.configure_and_load! ⇒ Object
59 60 61 62 |
# File 'lib/elasticonf.rb', line 59 def configure_and_load! configure { |config| yield(config) } load! end |
.load!(env = nil) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/elasticonf.rb', line 23 def load!(env = nil) config_file = config.config_root.join(config.config_file + '.yml') config.env = env if env unless File.exists?(config_file) raise "Config file #{config_file} not found. Cannot continue" end loader = Loader[YAML.load_file(config_file)] env_config_file = config.config_root.join(config.config_file, "#{config.env}.yml") if File.exists?(env_config_file) loader = loader.deep_merge(Loader[YAML.load_file(env_config_file)]) end local_config_file = config.config_root.join(config.config_file + '.local.yml') if File.exists?(local_config_file) loader = loader.deep_merge(Loader[YAML.load_file(local_config_file)]) end if Kernel.const_defined?(config.const_name) config.raise_if_already_initialized_constant ? raise("Cannot set constant #{config.const_name} because it is already initialized") : Kernel.send(:remove_const, config.const_name) end Kernel.const_set config.const_name, loader end |
.reload! ⇒ Object
52 53 54 55 56 57 |
# File 'lib/elasticonf.rb', line 52 def reload! if Kernel.const_defined?(config.const_name) Kernel.send :remove_const, config.const_name end load! end |
.root ⇒ Object
11 12 13 |
# File 'lib/elasticonf.rb', line 11 def root @root ||= Pathname.new(File.(File.join(File.dirname(__FILE__), '..'))) end |