configoro 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1 @@
1
+ configoro
@@ -0,0 +1 @@
1
+ 1.9.3
data/Gemfile CHANGED
@@ -1,7 +1,6 @@
1
- source :rubygems
1
+ source 'https://rubygems.org'
2
2
 
3
3
  gem 'rails', '>= 3.0'
4
- #gem 'activesupport', '>= 3.0'
5
4
 
6
5
  group :development do
7
6
  # SPECS
@@ -1,14 +1,14 @@
1
1
  GEM
2
- remote: http://rubygems.org/
2
+ remote: https://rubygems.org/
3
3
  specs:
4
- RedCloth (4.2.7)
4
+ RedCloth (4.2.9)
5
5
  abstract (1.0.0)
6
- actionmailer (3.0.7)
7
- actionpack (= 3.0.7)
8
- mail (~> 2.2.15)
9
- actionpack (3.0.7)
10
- activemodel (= 3.0.7)
11
- activesupport (= 3.0.7)
6
+ actionmailer (3.0.8)
7
+ actionpack (= 3.0.8)
8
+ mail (~> 2.2.19)
9
+ actionpack (3.0.8)
10
+ activemodel (= 3.0.8)
11
+ activesupport (= 3.0.8)
12
12
  builder (~> 2.1.2)
13
13
  erubis (~> 2.6.6)
14
14
  i18n (~> 0.5.0)
@@ -16,69 +16,74 @@ GEM
16
16
  rack-mount (~> 0.6.14)
17
17
  rack-test (~> 0.5.7)
18
18
  tzinfo (~> 0.3.23)
19
- activemodel (3.0.7)
20
- activesupport (= 3.0.7)
19
+ activemodel (3.0.8)
20
+ activesupport (= 3.0.8)
21
21
  builder (~> 2.1.2)
22
22
  i18n (~> 0.5.0)
23
- activerecord (3.0.7)
24
- activemodel (= 3.0.7)
25
- activesupport (= 3.0.7)
26
- arel (~> 2.0.2)
23
+ activerecord (3.0.8)
24
+ activemodel (= 3.0.8)
25
+ activesupport (= 3.0.8)
26
+ arel (~> 2.0.10)
27
27
  tzinfo (~> 0.3.23)
28
- activeresource (3.0.7)
29
- activemodel (= 3.0.7)
30
- activesupport (= 3.0.7)
31
- activesupport (3.0.7)
32
- arel (2.0.9)
28
+ activeresource (3.0.8)
29
+ activemodel (= 3.0.8)
30
+ activesupport (= 3.0.8)
31
+ activesupport (3.0.8)
32
+ arel (2.0.10)
33
33
  builder (2.1.2)
34
- diff-lcs (1.1.2)
34
+ diff-lcs (1.2.4)
35
35
  erubis (2.6.6)
36
36
  abstract (>= 1.0.0)
37
37
  git (1.2.5)
38
38
  i18n (0.5.0)
39
- jeweler (1.6.0)
40
- bundler (~> 1.0.0)
39
+ jeweler (1.8.4)
40
+ bundler (~> 1.0)
41
41
  git (>= 1.2.5)
42
42
  rake
43
+ rdoc
44
+ json (1.7.7)
43
45
  mail (2.2.19)
44
46
  activesupport (>= 2.3.6)
45
47
  i18n (>= 0.4.0)
46
48
  mime-types (~> 1.16)
47
49
  treetop (~> 1.4.8)
48
- mime-types (1.16)
49
- polyglot (0.3.1)
50
- rack (1.2.2)
50
+ mime-types (1.23)
51
+ polyglot (0.3.3)
52
+ rack (1.2.8)
51
53
  rack-mount (0.6.14)
52
54
  rack (>= 1.0.0)
53
55
  rack-test (0.5.7)
54
56
  rack (>= 1.0)
55
- rails (3.0.7)
56
- actionmailer (= 3.0.7)
57
- actionpack (= 3.0.7)
58
- activerecord (= 3.0.7)
59
- activeresource (= 3.0.7)
60
- activesupport (= 3.0.7)
57
+ rails (3.0.8)
58
+ actionmailer (= 3.0.8)
59
+ actionpack (= 3.0.8)
60
+ activerecord (= 3.0.8)
61
+ activeresource (= 3.0.8)
62
+ activesupport (= 3.0.8)
61
63
  bundler (~> 1.0)
62
- railties (= 3.0.7)
63
- railties (3.0.7)
64
- actionpack (= 3.0.7)
65
- activesupport (= 3.0.7)
64
+ railties (= 3.0.8)
65
+ railties (3.0.8)
66
+ actionpack (= 3.0.8)
67
+ activesupport (= 3.0.8)
66
68
  rake (>= 0.8.7)
67
69
  thor (~> 0.14.4)
68
- rake (0.8.7)
69
- rspec (2.5.0)
70
- rspec-core (~> 2.5.0)
71
- rspec-expectations (~> 2.5.0)
72
- rspec-mocks (~> 2.5.0)
73
- rspec-core (2.5.2)
74
- rspec-expectations (2.5.0)
75
- diff-lcs (~> 1.1.2)
76
- rspec-mocks (2.5.0)
70
+ rake (10.0.4)
71
+ rdoc (4.0.1)
72
+ json (~> 1.4)
73
+ rspec (2.13.0)
74
+ rspec-core (~> 2.13.0)
75
+ rspec-expectations (~> 2.13.0)
76
+ rspec-mocks (~> 2.13.0)
77
+ rspec-core (2.13.1)
78
+ rspec-expectations (2.13.0)
79
+ diff-lcs (>= 1.1.3, < 2.0)
80
+ rspec-mocks (2.13.1)
77
81
  thor (0.14.6)
78
- treetop (1.4.9)
82
+ treetop (1.4.12)
83
+ polyglot
79
84
  polyglot (>= 0.3.1)
80
- tzinfo (0.3.27)
81
- yard (0.6.8)
85
+ tzinfo (0.3.37)
86
+ yard (0.8.6.1)
82
87
 
83
88
  PLATFORMS
84
89
  ruby
@@ -70,6 +70,10 @@ Configuration is stored within the @config/environments@ directory of your Rails
70
70
  app. Files ending in ".yml" are loaded from the @common/@ subdirectory and a
71
71
  subdirectory named after the current environment.
72
72
 
73
+ Configuration files are preprocessed as ERB, in the same way that Rails
74
+ preprocesses @config/database.yml@. This allows dynamic configuration,
75
+ e.g. @host: <%= ENV["DB_HOST"] || "localhost" %>@.
76
+
73
77
  Each file goes into its own hash in the configuration. For example, if you
74
78
  placed a file called @memcache.yml@ within @config/environments/development@,
75
79
  you would be able to access your Memcache timeout using
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.0
1
+ 1.2.0
@@ -4,14 +4,14 @@
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
- s.name = %q{configoro}
8
- s.version = "1.1.0"
7
+ s.name = "configoro"
8
+ s.version = "1.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = [%q{Tim Morgan}]
12
- s.date = %q{2011-05-09}
13
- s.description = %q{Creates a YourApp::Configuration object whose methods are generated from environment-specific YAML files.}
14
- s.email = %q{git@timothymorgan.info}
11
+ s.authors = ["Tim Morgan"]
12
+ s.date = "2013-04-25"
13
+ s.description = "Creates a YourApp::Configuration object whose methods are generated from environment-specific YAML files."
14
+ s.email = "git@timothymorgan.info"
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE.txt",
17
17
  "README.textile"
@@ -19,6 +19,8 @@ Gem::Specification.new do |s|
19
19
  s.files = [
20
20
  ".document",
21
21
  ".rspec",
22
+ ".ruby-gemset",
23
+ ".ruby-version",
22
24
  "Gemfile",
23
25
  "Gemfile.lock",
24
26
  "LICENSE.txt",
@@ -34,17 +36,20 @@ Gem::Specification.new do |s|
34
36
  "spec/configoro/hash_spec.rb",
35
37
  "spec/configoro_spec.rb",
36
38
  "spec/data/config/environments/common/basic.yml",
39
+ "spec/data/config/environments/common/erb_test.yml",
37
40
  "spec/data/config/environments/common/hash_test.yml",
38
41
  "spec/data/config/environments/development/basic.yml",
39
42
  "spec/data/config/environments/development/hash_test.yml",
40
43
  "spec/data/config/environments/production/basic.yml",
44
+ "spec/data/other/common/basic.yml",
45
+ "spec/data/other/development/basic.yml",
41
46
  "spec/spec_helper.rb"
42
47
  ]
43
- s.homepage = %q{http://github.com/RISCfuture/configoro}
44
- s.licenses = [%q{MIT}]
45
- s.require_paths = [%q{lib}]
46
- s.rubygems_version = %q{1.8.1}
47
- s.summary = %q{Configuration object and YAML-based storage for Rails apps}
48
+ s.homepage = "http://github.com/RISCfuture/configoro"
49
+ s.licenses = ["MIT"]
50
+ s.require_paths = ["lib"]
51
+ s.rubygems_version = "1.8.25"
52
+ s.summary = "Configuration object and YAML-based storage for Rails apps"
48
53
 
49
54
  if s.respond_to? :specification_version then
50
55
  s.specification_version = 3
@@ -1,5 +1,6 @@
1
1
  raise "Configoro must be used in the context of a Rails 3 application" unless defined?(Rails)
2
2
 
3
+ require 'erb'
3
4
  require 'yaml'
4
5
  require 'bundler'
5
6
  Bundler.setup
@@ -14,21 +14,57 @@ module Configoro
14
14
  # @MyApp::Configuration@ (assuming an application named @MyApp@).
15
15
 
16
16
  def self.initialize
17
- namespace.const_set :Configuration, build_hash(Rails.env)
17
+ namespace.const_set :Configuration, load_environment(Rails.env)
18
18
  end
19
19
 
20
- private
20
+ # The search paths Configoro uses to locate configuration files. By default
21
+ # this list contains one item, `RAILS_ROOT/config/environments`. You can edit
22
+ # this list to add your own search paths. Any such paths should have
23
+ # subdirectories for each environment, and `common`, as expected by Configoro.
24
+ #
25
+ # Be sure to add paths before the Configoro initializer is called (see the
26
+ # example).
27
+ #
28
+ # Paths are processed in the order they appear in this array.
29
+ #
30
+ # @return [Array<String>] An editable array of search paths.
31
+ #
32
+ # @example Adding additional paths (application.rn)
33
+ # config.before_initialize do
34
+ # Configoro.paths << '/my/custom/path'
35
+ # end
21
36
 
22
- def self.build_hash(env)
23
- config = Hash.new
37
+ def self.paths
38
+ @paths ||= begin
39
+ paths = []
40
+ paths << "#{Rails.root}/config/environments" if defined?(Rails)
41
+ paths
42
+ end
43
+ end
24
44
 
25
- load_data config, 'common'
26
- load_data config, env
45
+ # Loads the configuration for an environment and returns it as a {Hash}. Use
46
+ # this method to access Configoro options outside the context of your Rails
47
+ # app. You will need to configure paths first (see example).
48
+ #
49
+ # @param [String] env The Rails environment.
50
+ # @return [Configoro::Hash] The configuration for that environment.
51
+ #
52
+ # @example Accessing Configoro options outside of Rails
53
+ # Configoro.paths << "#{rails_root}/config/environments"
54
+ # Configoro.load_environment(rails_env) #=> { ... }
27
55
 
56
+ def self.load_environment(env)
57
+ config = Hash.new
58
+ load_data config, env
28
59
  config
29
60
  end
30
61
 
62
+ private
63
+
31
64
  def self.load_data(config, env)
32
- Dir.glob("#{Rails.root}/config/environments/#{env}/*.yml").sort.each { |file| config << file }
65
+ paths.each do |path|
66
+ Dir.glob("#{path}/common/*.yml").sort.each { |file| config << file }
67
+ Dir.glob("#{path}/#{env}/*.yml").sort.each { |file| config << file }
68
+ end
33
69
  end
34
70
  end
@@ -30,7 +30,7 @@ class Configoro::Hash < HashWithIndifferentAccess
30
30
  when String
31
31
  raise ArgumentError, "Only files ending in .yml can be added" unless File.extname(hsh_or_path) == '.yml'
32
32
  return self unless File.exist?(hsh_or_path)
33
- data = YAML.load_file(hsh_or_path)
33
+ data = load_preprocessed_yaml(hsh_or_path)
34
34
  deep_merge! File.basename(hsh_or_path, ".yml") => data
35
35
  when ::Hash
36
36
  deep_merge! hsh_or_path
@@ -146,4 +146,9 @@ class Configoro::Hash < HashWithIndifferentAccess
146
146
 
147
147
  raise NameError, "undefined local variable or method `#{meth}' for #{self.inspect}"
148
148
  end
149
+
150
+ def load_preprocessed_yaml(path)
151
+ YAML.load(ERB.new(IO.read(path)).result)
152
+ end
153
+
149
154
  end
@@ -95,6 +95,11 @@ describe Configoro::Hash do
95
95
  subject << "example.yml"
96
96
  subject.should be_empty
97
97
  end
98
+
99
+ it "should preprocess YAML file as ERB" do
100
+ subject << "#{File.dirname __FILE__}/../data/config/environments/common/erb_test.yml"
101
+ subject.erb_test.sum.should == 2
102
+ end
98
103
  end
99
104
 
100
105
  describe "#deep_merge!" do
@@ -34,7 +34,25 @@ describe Configoro do
34
34
  it "should not complain when there is no directory for the current environment" do
35
35
  Rails.stub!(:env).and_return('unknown')
36
36
  Configoro.initialize
37
- MyApp::Configuration.should eql({"basic"=>{"common_only"=>"common", "env_name"=>"common"}, "hash_test"=>{"akey"=>"value", "subhash"=>{"key1"=>"val1", "key2"=>"val2"}}})
37
+ MyApp::Configuration.should eql({"basic"=>{"common_only"=>"common", "env_name"=>"common"}, "erb_test" => {"sum" => 2}, "hash_test"=>{"akey"=>"value", "subhash"=>{"key1"=>"val1", "key2"=>"val2"}}})
38
+ end
39
+
40
+ context "[custom search paths]" do
41
+ before(:each) { Configoro.instance_variable_set :@paths, nil }
42
+
43
+ it "should use common configuration under a custom search path" do
44
+ Rails.stub!(:env).and_return('unknown')
45
+ Configoro.paths << File.join(File.dirname(__FILE__), 'data', 'other')
46
+ Configoro.initialize
47
+ MyApp::Configuration.basic.env_name.should eql('other_common')
48
+ end
49
+
50
+ it "should use environment-specific configuration under a custom search path" do
51
+ Rails.stub!(:env).and_return('development')
52
+ Configoro.paths << File.join(File.dirname(__FILE__), 'data', 'other')
53
+ Configoro.initialize
54
+ MyApp::Configuration.basic.env_name.should eql('other_development')
55
+ end
38
56
  end
39
57
  end
40
58
  end
@@ -0,0 +1,2 @@
1
+ ---
2
+ sum: <%= 1 + 1 %>
@@ -0,0 +1,2 @@
1
+ ---
2
+ env_name: other_common
@@ -0,0 +1,2 @@
1
+ ---
2
+ env_name: other_development
metadata CHANGED
@@ -1,95 +1,125 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: configoro
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.2.0
4
5
  prerelease:
5
- version: 1.1.0
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Tim Morgan
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2011-05-09 00:00:00 Z
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
12
+ date: 2013-04-25 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
16
15
  name: rails
17
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
18
17
  none: false
19
- requirements:
20
- - - ">="
21
- - !ruby/object:Gem::Version
22
- version: "3.0"
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '3.0'
23
22
  type: :runtime
24
23
  prerelease: false
25
- version_requirements: *id001
26
- - !ruby/object:Gem::Dependency
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '3.0'
30
+ - !ruby/object:Gem::Dependency
27
31
  name: rspec
28
- requirement: &id002 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
29
33
  none: false
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: "0"
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
34
38
  type: :development
35
39
  prerelease: false
36
- version_requirements: *id002
37
- - !ruby/object:Gem::Dependency
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
38
47
  name: yard
39
- requirement: &id003 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
40
49
  none: false
41
- requirements:
42
- - - ">="
43
- - !ruby/object:Gem::Version
44
- version: "0"
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
45
54
  type: :development
46
55
  prerelease: false
47
- version_requirements: *id003
48
- - !ruby/object:Gem::Dependency
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
49
63
  name: RedCloth
50
- requirement: &id004 !ruby/object:Gem::Requirement
64
+ requirement: !ruby/object:Gem::Requirement
51
65
  none: false
52
- requirements:
53
- - - ">="
54
- - !ruby/object:Gem::Version
55
- version: "0"
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
56
70
  type: :development
57
71
  prerelease: false
58
- version_requirements: *id004
59
- - !ruby/object:Gem::Dependency
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
60
79
  name: bundler
61
- requirement: &id005 !ruby/object:Gem::Requirement
80
+ requirement: !ruby/object:Gem::Requirement
62
81
  none: false
63
- requirements:
64
- - - ">="
65
- - !ruby/object:Gem::Version
66
- version: "0"
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
67
86
  type: :development
68
87
  prerelease: false
69
- version_requirements: *id005
70
- - !ruby/object:Gem::Dependency
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
71
95
  name: jeweler
72
- requirement: &id006 !ruby/object:Gem::Requirement
96
+ requirement: !ruby/object:Gem::Requirement
73
97
  none: false
74
- requirements:
75
- - - ">="
76
- - !ruby/object:Gem::Version
77
- version: "0"
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
78
102
  type: :development
79
103
  prerelease: false
80
- version_requirements: *id006
81
- description: Creates a YourApp::Configuration object whose methods are generated from environment-specific YAML files.
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ description: Creates a YourApp::Configuration object whose methods are generated from
111
+ environment-specific YAML files.
82
112
  email: git@timothymorgan.info
83
113
  executables: []
84
-
85
114
  extensions: []
86
-
87
- extra_rdoc_files:
115
+ extra_rdoc_files:
88
116
  - LICENSE.txt
89
117
  - README.textile
90
- files:
118
+ files:
91
119
  - .document
92
120
  - .rspec
121
+ - .ruby-gemset
122
+ - .ruby-version
93
123
  - Gemfile
94
124
  - Gemfile.lock
95
125
  - LICENSE.txt
@@ -105,40 +135,40 @@ files:
105
135
  - spec/configoro/hash_spec.rb
106
136
  - spec/configoro_spec.rb
107
137
  - spec/data/config/environments/common/basic.yml
138
+ - spec/data/config/environments/common/erb_test.yml
108
139
  - spec/data/config/environments/common/hash_test.yml
109
140
  - spec/data/config/environments/development/basic.yml
110
141
  - spec/data/config/environments/development/hash_test.yml
111
142
  - spec/data/config/environments/production/basic.yml
143
+ - spec/data/other/common/basic.yml
144
+ - spec/data/other/development/basic.yml
112
145
  - spec/spec_helper.rb
113
146
  homepage: http://github.com/RISCfuture/configoro
114
- licenses:
147
+ licenses:
115
148
  - MIT
116
149
  post_install_message:
117
150
  rdoc_options: []
118
-
119
- require_paths:
151
+ require_paths:
120
152
  - lib
121
- required_ruby_version: !ruby/object:Gem::Requirement
153
+ required_ruby_version: !ruby/object:Gem::Requirement
122
154
  none: false
123
- requirements:
124
- - - ">="
125
- - !ruby/object:Gem::Version
126
- hash: 3499907636224046396
127
- segments:
155
+ requirements:
156
+ - - ! '>='
157
+ - !ruby/object:Gem::Version
158
+ version: '0'
159
+ segments:
128
160
  - 0
129
- version: "0"
130
- required_rubygems_version: !ruby/object:Gem::Requirement
161
+ hash: -4443263758316120902
162
+ required_rubygems_version: !ruby/object:Gem::Requirement
131
163
  none: false
132
- requirements:
133
- - - ">="
134
- - !ruby/object:Gem::Version
135
- version: "0"
164
+ requirements:
165
+ - - ! '>='
166
+ - !ruby/object:Gem::Version
167
+ version: '0'
136
168
  requirements: []
137
-
138
169
  rubyforge_project:
139
- rubygems_version: 1.8.1
170
+ rubygems_version: 1.8.25
140
171
  signing_key:
141
172
  specification_version: 3
142
173
  summary: Configuration object and YAML-based storage for Rails apps
143
174
  test_files: []
144
-