webmat-local_config 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/LICENSE +20 -0
- data/README.rdoc +29 -0
- data/VERSION.yml +4 -0
- data/lib/local_config.rb +14 -0
- data/test/local_config_test.rb +53 -0
- data/test/test_helper.rb +15 -0
- data/test/test_rails_root/config/no_env.yml +1 -0
- data/test/test_rails_root/config/with_local.local.yml +2 -0
- data/test/test_rails_root/config/with_local.yml +2 -0
- data/test/test_rails_root/config/without_local.yml +2 -0
- metadata +66 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Mathieu Martin
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
= local_config
|
2
|
+
|
3
|
+
local_config is a micro plugin that encapsulates the pattern of loading either the official foo.yml
|
4
|
+
config file or the developer's personal foo.local.yml file.
|
5
|
+
|
6
|
+
== Example
|
7
|
+
|
8
|
+
LocalConfig.load_config('database')
|
9
|
+
|
10
|
+
This loads RAILS_ROOT/config/database.local.yml if present. Otherwise loads database.yml.
|
11
|
+
Will return only the section related to the current RAILS_ENV by default.
|
12
|
+
|
13
|
+
If you have a file that isn't split in the usual RAILS_ENV sections, simply call
|
14
|
+
|
15
|
+
LocalConfig.load_environment_config('foo', :environment => false)
|
16
|
+
|
17
|
+
== Install
|
18
|
+
|
19
|
+
Whichever you prefer:
|
20
|
+
|
21
|
+
script/plugin install http://github.com/webmat/local_config.git
|
22
|
+
|
23
|
+
or
|
24
|
+
|
25
|
+
config.gem "webmat-local_config", :lib => 'local_config', :source => "http://gems.github.com"
|
26
|
+
|
27
|
+
== Copyright
|
28
|
+
|
29
|
+
Copyright (c) 2009 Mathieu Martin. See LICENSE for details.
|
data/VERSION.yml
ADDED
data/lib/local_config.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
module LocalConfig
|
4
|
+
def self.load_config(name, options={})
|
5
|
+
environment = options.has_key?(:environment) ? options[:environment] : true
|
6
|
+
|
7
|
+
personal_config_file = "#{RAILS_ROOT}/config/#{name}.local.yml"
|
8
|
+
shared_config_file = "#{RAILS_ROOT}/config/#{name}.yml"
|
9
|
+
config_file = File.exists?(personal_config_file) ? personal_config_file : shared_config_file
|
10
|
+
|
11
|
+
config = HashWithIndifferentAccess.new YAML.load(File.read(config_file))
|
12
|
+
environment ? config[RAILS_ENV] : config
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class LocalConfigTest < Test::Unit::TestCase
|
4
|
+
context "with RAILS_ENV set to 'development'" do
|
5
|
+
setup do
|
6
|
+
silence_warnings { ::RAILS_ENV = 'development' }
|
7
|
+
end
|
8
|
+
|
9
|
+
context "in the general case" do
|
10
|
+
setup do
|
11
|
+
@config = LocalConfig.load_config('without_local')
|
12
|
+
end
|
13
|
+
|
14
|
+
should "return the content of the hash for the current environment" do
|
15
|
+
assert !@config.has_key?(:development)
|
16
|
+
end
|
17
|
+
|
18
|
+
should "return a Rails' HashWithIndifferentAccess, for convenience's sake" do
|
19
|
+
assert_equal HashWithIndifferentAccess, @config.class
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context "reading with_local.yml" do
|
24
|
+
setup do
|
25
|
+
@config = LocalConfig.load_config('with_local')
|
26
|
+
end
|
27
|
+
|
28
|
+
should "return the values of the .local file" do
|
29
|
+
assert_equal 'local value', @config[:param]
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context "reading without_local.yml" do
|
34
|
+
setup do
|
35
|
+
@config = LocalConfig.load_config('without_local')
|
36
|
+
end
|
37
|
+
|
38
|
+
should "return the values of the .yml file" do
|
39
|
+
assert_equal 'never overridden', @config[:param]
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context "reading no_env.yml" do
|
45
|
+
setup do
|
46
|
+
@config = LocalConfig.load_config('no_env', :environment => false)
|
47
|
+
end
|
48
|
+
|
49
|
+
should "return the values of the .yml file" do
|
50
|
+
assert_equal 'value', @config[:param]
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'test/unit'
|
3
|
+
require 'shoulda'
|
4
|
+
require 'activesupport'
|
5
|
+
|
6
|
+
test_dir = File.dirname(__FILE__)
|
7
|
+
|
8
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
9
|
+
$LOAD_PATH.unshift(test_dir)
|
10
|
+
require 'local_config'
|
11
|
+
|
12
|
+
RAILS_ROOT = File.join test_dir, 'test_rails_root'
|
13
|
+
|
14
|
+
class Test::Unit::TestCase
|
15
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
param: value
|
metadata
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: webmat-local_config
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mathieu Martin
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-05-04 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description:
|
17
|
+
email: webmat@gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README.rdoc
|
24
|
+
- LICENSE
|
25
|
+
files:
|
26
|
+
- README.rdoc
|
27
|
+
- VERSION.yml
|
28
|
+
- lib/local_config.rb
|
29
|
+
- test/local_config_test.rb
|
30
|
+
- test/test_helper.rb
|
31
|
+
- test/test_rails_root
|
32
|
+
- test/test_rails_root/config
|
33
|
+
- test/test_rails_root/config/no_env.yml
|
34
|
+
- test/test_rails_root/config/with_local.local.yml
|
35
|
+
- test/test_rails_root/config/with_local.yml
|
36
|
+
- test/test_rails_root/config/without_local.yml
|
37
|
+
- LICENSE
|
38
|
+
has_rdoc: true
|
39
|
+
homepage: http://github.com/webmat/local_config
|
40
|
+
post_install_message:
|
41
|
+
rdoc_options:
|
42
|
+
- --inline-source
|
43
|
+
- --charset=UTF-8
|
44
|
+
require_paths:
|
45
|
+
- lib
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: "0"
|
51
|
+
version:
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: "0"
|
57
|
+
version:
|
58
|
+
requirements: []
|
59
|
+
|
60
|
+
rubyforge_project:
|
61
|
+
rubygems_version: 1.2.0
|
62
|
+
signing_key:
|
63
|
+
specification_version: 2
|
64
|
+
summary: "Micro plugin to solve a micro problem: loading either your .local.yml config file if it's there, or the official .yml otherwise."
|
65
|
+
test_files: []
|
66
|
+
|