simple_app_config 0.1.21 → 0.2.0
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/README.rdoc +8 -0
- data/VERSION +1 -1
- data/lib/simple_app_config.rb +3 -1
- data/simple_app_config.gemspec +7 -6
- data/test/simple_app_config_test.rb +22 -2
- metadata +17 -5
data/README.rdoc
CHANGED
@@ -43,6 +43,14 @@ Here is how a configuration file could look like:
|
|
43
43
|
puts Config.application
|
44
44
|
puts Config.payment['key']
|
45
45
|
|
46
|
+
Or if you prefer the hash syntax do
|
47
|
+
|
48
|
+
require 'simple_app_config'
|
49
|
+
Config = AppConfig.create("config/application.yml", :environment => 'development', :format => :hash)
|
50
|
+
|
51
|
+
puts Config.application
|
52
|
+
puts Config['payment']['key']
|
53
|
+
|
46
54
|
When used in a Rails project, create an initializer and add something like this:
|
47
55
|
|
48
56
|
require 'simple_app_config'
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/lib/simple_app_config.rb
CHANGED
@@ -1,11 +1,13 @@
|
|
1
1
|
require 'ostruct'
|
2
2
|
require 'erb'
|
3
|
+
require 'YAML'
|
3
4
|
class AppConfig
|
4
5
|
def self.create(yaml_file, options = {})
|
6
|
+
format = options[:format] || :struct
|
5
7
|
yaml_data = YAML::load(ERB.new(IO.read(yaml_file)).result)
|
6
8
|
data = {}
|
7
9
|
data = yaml_data.delete(options[:environment]) if options[:environment]
|
8
10
|
data.merge!(yaml_data)
|
9
|
-
OpenStruct.new(data)
|
11
|
+
format == :struct ? OpenStruct.new(data) : data
|
10
12
|
end
|
11
13
|
end
|
data/simple_app_config.gemspec
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{simple_app_config}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.2.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Patrick Huesler"]
|
12
|
-
s.date = %q{
|
12
|
+
s.date = %q{2010-06-25}
|
13
13
|
s.description = %q{Use yml and erb and specify environments and scopes}
|
14
14
|
s.email = %q{patrick.huesler@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -32,7 +32,7 @@ Gem::Specification.new do |s|
|
|
32
32
|
s.homepage = %q{http://github.com/phuesler/simple_app_config}
|
33
33
|
s.rdoc_options = ["--charset=UTF-8"]
|
34
34
|
s.require_paths = ["lib"]
|
35
|
-
s.rubygems_version = %q{1.3.
|
35
|
+
s.rubygems_version = %q{1.3.7}
|
36
36
|
s.summary = %q{A little helper to define and access the app configuration}
|
37
37
|
s.test_files = [
|
38
38
|
"test/simple_app_config_test.rb",
|
@@ -43,9 +43,10 @@ Gem::Specification.new do |s|
|
|
43
43
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
44
44
|
s.specification_version = 3
|
45
45
|
|
46
|
-
if Gem::Version.new(Gem::
|
46
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
47
47
|
else
|
48
48
|
end
|
49
49
|
else
|
50
50
|
end
|
51
51
|
end
|
52
|
+
|
@@ -6,10 +6,25 @@ class AppConfigTest < Test::Unit::TestCase
|
|
6
6
|
config = AppConfig.create(TEST_FILE)
|
7
7
|
assert_equal "RailsConfig", config.application
|
8
8
|
end
|
9
|
-
|
9
|
+
|
10
|
+
def test_hash_format
|
11
|
+
config = AppConfig.create(TEST_FILE,:format => :hash)
|
12
|
+
assert_equal 'RailsConfig', config['application']
|
13
|
+
end
|
14
|
+
|
10
15
|
def test_read_a_scoped_attribute
|
11
16
|
config = AppConfig.create(TEST_FILE, :environment => 'development')
|
12
17
|
assert_equal "development_payment_key", config.payment['key']
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_read_a_scoped_attribute_in_hash_format
|
21
|
+
config = AppConfig.create(TEST_FILE, :environment => 'development', :format => :hash)
|
22
|
+
assert_equal "development_payment_key", config['payment']['key']
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_read_a_scoped_attribute_in_hash_format
|
26
|
+
config = AppConfig.create(TEST_FILE, :environment => 'development', :format => :hash)
|
27
|
+
assert_equal "development_payment_key", config['payment']['key']
|
13
28
|
end
|
14
29
|
|
15
30
|
def test_attributes_are_inherited
|
@@ -17,8 +32,13 @@ class AppConfigTest < Test::Unit::TestCase
|
|
17
32
|
assert_equal "payment_key", config.payment['key']
|
18
33
|
end
|
19
34
|
|
35
|
+
def test_attributes_are_inherited_in_hash_format
|
36
|
+
config = AppConfig.create(TEST_FILE, :environment => 'production', :format => :hash)
|
37
|
+
assert_equal "payment_key", config['payment']['key']
|
38
|
+
end
|
39
|
+
|
20
40
|
def test_erb_rendering
|
21
41
|
config = AppConfig.create(TEST_FILE)
|
22
42
|
assert_equal 'VERSION', config.version
|
23
|
-
end
|
43
|
+
end
|
24
44
|
end
|
metadata
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_app_config
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 23
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 2
|
9
|
+
- 0
|
10
|
+
version: 0.2.0
|
5
11
|
platform: ruby
|
6
12
|
authors:
|
7
13
|
- Patrick Huesler
|
@@ -9,7 +15,7 @@ autorequire:
|
|
9
15
|
bindir: bin
|
10
16
|
cert_chain: []
|
11
17
|
|
12
|
-
date:
|
18
|
+
date: 2010-06-25 00:00:00 +02:00
|
13
19
|
default_executable:
|
14
20
|
dependencies: []
|
15
21
|
|
@@ -44,21 +50,27 @@ rdoc_options:
|
|
44
50
|
require_paths:
|
45
51
|
- lib
|
46
52
|
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
47
54
|
requirements:
|
48
55
|
- - ">="
|
49
56
|
- !ruby/object:Gem::Version
|
57
|
+
hash: 3
|
58
|
+
segments:
|
59
|
+
- 0
|
50
60
|
version: "0"
|
51
|
-
version:
|
52
61
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
53
63
|
requirements:
|
54
64
|
- - ">="
|
55
65
|
- !ruby/object:Gem::Version
|
66
|
+
hash: 3
|
67
|
+
segments:
|
68
|
+
- 0
|
56
69
|
version: "0"
|
57
|
-
version:
|
58
70
|
requirements: []
|
59
71
|
|
60
72
|
rubyforge_project:
|
61
|
-
rubygems_version: 1.3.
|
73
|
+
rubygems_version: 1.3.7
|
62
74
|
signing_key:
|
63
75
|
specification_version: 3
|
64
76
|
summary: A little helper to define and access the app configuration
|