jcnetdev-app_config 1.0 → 1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/app_config.gemspec +2 -2
- data/lib/app_config.rb +17 -11
- data/test/app_config_test.rb +3 -1
- metadata +2 -2
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.
|
4
|
-
s.date = '2008-07-
|
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
|
-
|
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(
|
12
|
-
|
13
|
-
|
14
|
-
|
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)
|
data/test/app_config_test.rb
CHANGED
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.
|
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-
|
13
|
+
date: 2008-07-24 00:00:00 -07:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|