jcnetdev-app_config 1.0 → 1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/app_config.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'app_config'
3
- s.version = '1.0'
4
- s.date = '2008-07-04'
3
+ s.version = '1.1'
4
+ s.date = '2008-07-24'
5
5
 
6
6
  s.summary = "Application level configuration"
7
7
  s.description = "Allow application wide configuration settings via YML files"
data/lib/app_config.rb CHANGED
@@ -4,21 +4,27 @@ require 'erb'
4
4
 
5
5
  # == Summary
6
6
  # This is API documentation, NOT documentation on how to use this plugin. For that, see the README.
7
- module ApplicationConfig
7
+ class ApplicationConfig
8
+
9
+ cattr_accessor :conf_paths
8
10
 
9
11
  # Create a config object (OpenStruct) from a yaml file. If a second yaml file is given, then the sections of that file will overwrite the sections
10
12
  # if the first file if they exist in the first file.
11
- def self.load_files(conf_path_1, conf_path_2 = nil)
12
-
13
- conf1 = YAML.load(ERB.new(IO.read(conf_path_1)).result) if conf_path_1 and File.exists?(conf_path_1)
14
- conf1 = {} if !conf1 or conf1.empty?
15
-
16
- conf2 = YAML.load(ERB.new(IO.read(conf_path_2)).result) if conf_path_2 and File.exists?(conf_path_2)
17
- conf2 = {} if !conf2 or conf2.empty?
18
-
19
- conf = conf1.merge(conf2)
20
- (!conf or conf.empty?) ? OpenStruct.new : convert(conf)
13
+ def self.load_files(*conf_load_paths)
14
+ self.conf_paths = []
15
+ self.conf_paths += conf_load_paths
16
+ self.conf_paths.uniq!
21
17
 
18
+ reload!
19
+ end
20
+
21
+ def self.reload!
22
+ conf = {}
23
+ conf_paths.each do |path|
24
+ new_conf = YAML.load(ERB.new(IO.read(path)).result) if path and File.exists?(path)
25
+ conf.merge!(new_conf) if new_conf
26
+ end
27
+ return convert(conf)
22
28
  end
23
29
 
24
30
  # Recursively converts Hashes to OpenStructs (including Hashes inside Arrays)
@@ -1,5 +1,7 @@
1
+ require 'rubygems'
1
2
  require 'test/unit'
2
- require 'app_config'
3
+ require 'active_support'
4
+ require 'lib/app_config'
3
5
 
4
6
  class AppConfigTest < Test::Unit::TestCase
5
7
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jcnetdev-app_config
3
3
  version: !ruby/object:Gem::Version
4
- version: "1.0"
4
+ version: "1.1"
5
5
  platform: ruby
6
6
  authors:
7
7
  - RailsJedi
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2008-07-04 00:00:00 -07:00
13
+ date: 2008-07-24 00:00:00 -07:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency