simpleconfig 1.1.3 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +8 -0
- data/CHANGELOG.md +25 -0
- data/Gemfile +3 -0
- data/MIT-LICENSE +20 -0
- data/{README.textile → README.md} +45 -42
- data/Rakefile +57 -55
- data/lib/simple_config.rb +41 -29
- data/lib/simple_config/controller_mixin.rb +6 -0
- data/lib/simple_config/utilities.rb +5 -0
- data/lib/simpleconfig.rb +1 -0
- data/simpleconfig.gemspec +36 -0
- data/test/controller_mixin_test.rb +1 -3
- data/test/network_host_test.rb +1 -2
- data/test/simple_config_functional_test.rb +0 -3
- data/test/simple_config_test.rb +36 -4
- data/test/test_helper.rb +6 -0
- data/test/yaml_parser_test.rb +1 -3
- metadata +83 -42
data/.gitignore
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
## master
|
4
|
+
|
5
|
+
- Updated Rakefile.
|
6
|
+
- Added support for Bundler.
|
7
|
+
- Added ability to duplicate a config object using SimpleConfig::Config#dup (GH-14). [Thanks @andriusch]
|
8
|
+
- Added SimpleConfig::Config#merge and SimpleConfig::Config#merge! (GH-14). [Thanks @andriusch]
|
9
|
+
- Deprecated SimpleConfig::Utilities.
|
10
|
+
- Deprecated SimpleConfig::ControllerMixin.
|
11
|
+
|
12
|
+
## 1.1
|
13
|
+
|
14
|
+
- Added #to_hash method (via markschmidt)
|
15
|
+
|
16
|
+
## 1.0.2
|
17
|
+
|
18
|
+
- Added 'application.rb' to the list of default config files for non-environment specific settings (via weppos)
|
19
|
+
- SimpleConfig can be loaded using require 'simpleconfig' as well as 'simple_config'
|
20
|
+
- Adhere to Rails conventions for submodules and directories (via lazyatom)
|
21
|
+
|
22
|
+
## 1.0.1
|
23
|
+
|
24
|
+
- Removed dependency on ActiveSupport
|
25
|
+
- Converted from Rails plugin to a gem
|
data/Gemfile
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 Luke Redpath
|
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.
|
@@ -7,7 +7,10 @@ One simple solution is to simply put all of your app configuration into a YAML f
|
|
7
7
|
|
8
8
|
SimpleConfig was originally written against Rails 1.x and may still work but as of version 1.1.1 the minimum required Rails version is 2.3.5. You may be able to use it with older versions of Rails but YMMV.
|
9
9
|
|
10
|
-
|
10
|
+
WARNING: SimpleConfig 1.x is not fully compatible with Rails 3. It works, but the rake tasks are not automatically loaded. Please upgrade to SimpleConfig 2.0 if you are using Rails 3.
|
11
|
+
|
12
|
+
|
13
|
+
## Getting started
|
11
14
|
|
12
15
|
The plugin comes with a rake task to get you up and running quickly, so start by running that.
|
13
16
|
|
@@ -17,7 +20,7 @@ This will create a config/settings folder and a blank settings file for each of
|
|
17
20
|
|
18
21
|
Now, if you open up the configuration.rb initializer, you will see something like this:
|
19
22
|
|
20
|
-
|
23
|
+
```ruby
|
21
24
|
SimpleConfig.for :application do
|
22
25
|
|
23
26
|
# your app configuration here
|
@@ -26,46 +29,46 @@ SimpleConfig.for :application do
|
|
26
29
|
load File.join(Rails.root, 'config', "settings", "local.rb"), :if_exists? => true
|
27
30
|
|
28
31
|
end
|
29
|
-
|
32
|
+
```
|
30
33
|
|
31
|
-
This is where you can set any configuration variables that are required across all Rails environments. The
|
34
|
+
This is where you can set any configuration variables that are required across all Rails environments. The `load` method works just like Ruby's built-in load method, except the contents of the file it loads are evaluated within the context of the `SimpleConfig.for` block. The `:if_exists?` flag, when set to true, means that the file will only be loaded if it exists, otherwise it will simply be ignored.
|
32
35
|
|
33
36
|
Variables can be overwritten, and are defined in the order that they are loaded, so you can set up default values in the above file and override them in the environment files.
|
34
37
|
|
35
38
|
As well as loading a settings file for your current Rails environment, a file called "local.rb" is loaded which is designed as a place for you to override variables specific to your own development environment -- you can just keep a copy of this locally without having to check it into your version control system[1].
|
36
39
|
|
37
|
-
|
40
|
+
## Variables
|
38
41
|
|
39
|
-
|
42
|
+
### Setting Variables
|
40
43
|
|
41
|
-
Setting variables is simple and will be familiar to anybody who has used Capistrano. Whether in your main
|
44
|
+
Setting variables is simple and will be familiar to anybody who has used Capistrano. Whether in your main `SimpleConfig.for` block in configuration.rb, or one of your external settings files, use the `set` method:
|
42
45
|
|
43
|
-
|
46
|
+
```ruby
|
44
47
|
SimpleConfig.for :application do
|
45
48
|
set :my_variable, 'hello world'
|
46
49
|
end
|
47
|
-
|
50
|
+
```
|
48
51
|
|
49
52
|
SimpleConfig also supports a form of namespacing that allows you to group logical sets of variables together:
|
50
53
|
|
51
|
-
|
54
|
+
```ruby
|
52
55
|
SimpleConfig.for :application do
|
53
56
|
group :awesome_stuff do
|
54
57
|
set :my_variable, 'hello world'
|
55
58
|
end
|
56
59
|
end
|
57
|
-
|
60
|
+
```
|
58
61
|
|
59
|
-
Both the
|
62
|
+
Both the `set` and `load` methods are available within `group` blocks and files loaded inside groups will be evaluated in the context of that group.
|
60
63
|
|
61
64
|
Whilst I'd recommend not nesting your groups more than one-level, there is no limit on how deep they can be nested.
|
62
65
|
|
63
|
-
|
66
|
+
### Unsetting variables
|
64
67
|
|
65
|
-
Sometimes you might want to completely delete a variable from the collection. Simply setting its value to nil doesn't work because
|
66
|
-
You can delete a variable using the
|
68
|
+
Sometimes you might want to completely delete a variable from the collection. Simply setting its value to nil doesn't work because `nil` might be a valid value.
|
69
|
+
You can delete a variable using the `unset` method.
|
67
70
|
|
68
|
-
|
71
|
+
```ruby
|
69
72
|
SimpleConfig.for :application do
|
70
73
|
set :my_variable, 'hello world'
|
71
74
|
|
@@ -73,16 +76,16 @@ SimpleConfig.for :application do
|
|
73
76
|
|
74
77
|
unset :my_variable
|
75
78
|
end
|
76
|
-
|
79
|
+
```
|
77
80
|
|
78
81
|
For instance, this is useful to remove global settings at environment level instead of overwriting the default value with a nonsense-one.
|
79
|
-
|
82
|
+
`unset` returns the value of the variable just in case you need to use it elsewhere.
|
80
83
|
|
81
|
-
|
84
|
+
### Does a specific variable exist?
|
82
85
|
|
83
|
-
I don't know but you can check it yourself using
|
86
|
+
I don't know but you can check it yourself using `exists?` method.
|
84
87
|
|
85
|
-
|
88
|
+
```ruby
|
86
89
|
config = SimpleConfig.for :application do
|
87
90
|
set :my_variable, 'hello world'
|
88
91
|
end
|
@@ -90,55 +93,55 @@ end
|
|
90
93
|
# write some nice code
|
91
94
|
config.exists? :my_variable # => true
|
92
95
|
config.exists? :your_variable # => false
|
93
|
-
|
96
|
+
```
|
94
97
|
|
95
|
-
|
98
|
+
## Accessing your configuration
|
96
99
|
|
97
|
-
SimpleConfig allows you set as many separate configurations as you like using the
|
100
|
+
SimpleConfig allows you set as many separate configurations as you like using the `SimpleConfig.for` method, which takes a symbol representing the configuration name, although most people will just create a single "application" config as above. To access this config from anywhere in your application, you can also use `SimpleConfig.for` method without a block, which always returns the named configuration object.
|
98
101
|
|
99
|
-
It is worth pointing out that
|
102
|
+
It is worth pointing out that `SimpleConfig.for` provides an almost singleton-style access to a particular named config. Calling `SimpleConfig.for` with a block a second time for a particular named configuration will simply extend the existing configuration, not overwrite it.
|
100
103
|
|
101
|
-
Once you have a reference to your configuration object, you can access variables using method access. Given the above example,
|
104
|
+
Once you have a reference to your configuration object, you can access variables using method access. Given the above example, `:my_variable` would be accessed in the following way:
|
102
105
|
|
103
|
-
|
106
|
+
```ruby
|
104
107
|
config = SimpleConfig.for(:application)
|
105
108
|
config.my_variable # => "hello world"
|
106
|
-
|
109
|
+
```
|
107
110
|
|
108
111
|
Accessing grouped variables works as you would expect:
|
109
112
|
|
110
|
-
|
113
|
+
```ruby
|
111
114
|
config = SimpleConfig.for(:application)
|
112
115
|
config.awesome_stuff.my_variable # => "hello world"
|
113
|
-
|
116
|
+
```
|
114
117
|
|
115
|
-
|
118
|
+
## Using your configuration in your Rails app
|
116
119
|
|
117
|
-
The plugin provides a convenient mixin for your
|
120
|
+
The plugin provides a convenient mixin for your `ApplicationController` to make configuration access as simple as possible. Assuming a configuration called "application" (as in the above examples), it defines a `config` method which can be used in any of your controllers. It also defines this as a method as a view helper using the Rails `helper_method` macro so you can access configuration data in your views.
|
118
121
|
|
119
|
-
Note - there is no direct way of accessing your configuration variables in your models other than making a direct call to
|
122
|
+
Note - there is no direct way of accessing your configuration variables in your models other than making a direct call to `SimpleConfig.for`. I'd recommend designing your models in such a way that configuration data can be passed into them at runtime as method arguments by your controller to avoid coupling your model to SimpleConfig.
|
120
123
|
|
121
|
-
To use the mixin, simply include it in your
|
124
|
+
To use the mixin, simply include it in your `ApplicationController`:
|
122
125
|
|
123
|
-
|
126
|
+
```ruby
|
124
127
|
class ApplicationController < ActionController::Base
|
125
128
|
include SimpleConfig::ControllerMixin
|
126
129
|
end
|
127
|
-
|
130
|
+
```
|
128
131
|
|
129
132
|
Then in your controllers:
|
130
133
|
|
131
|
-
|
134
|
+
```ruby
|
132
135
|
class MyController < ApplicationController
|
133
136
|
def index
|
134
137
|
render :text => config.my_config_variable
|
135
138
|
end
|
136
139
|
end
|
137
|
-
|
140
|
+
```
|
138
141
|
|
139
|
-
The mixin provides also a class-level
|
142
|
+
The mixin provides also a class-level `config` method to access the configuration when you don't have a controller instance available.
|
140
143
|
|
141
|
-
|
144
|
+
```ruby
|
142
145
|
class MyController < ApplicationController
|
143
146
|
protect_from_forgery :secret => config.secret_token
|
144
147
|
|
@@ -146,6 +149,6 @@ class MyController < ApplicationController
|
|
146
149
|
render :text => config.my_config_variable
|
147
150
|
end
|
148
151
|
end
|
149
|
-
|
152
|
+
```
|
150
153
|
|
151
|
-
fn1(footnote). In fact, I recommend you make sure your version control system ignores this file otherwise you risk checking in a file that will override values in production! If you are using Subversion, simply add local.rb to the svn:ignore property for the config/settings folder.
|
154
|
+
fn1(footnote). In fact, I recommend you make sure your version control system ignores this file otherwise you risk checking in a file that will override values in production! If you are using Subversion, simply add local.rb to the svn:ignore property for the config/settings folder.
|
data/Rakefile
CHANGED
@@ -1,27 +1,11 @@
|
|
1
|
-
require '
|
2
|
-
require '
|
3
|
-
require '
|
4
|
-
require "rubygems"
|
5
|
-
require "rubygems/package_task"
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rubygems/package_task'
|
3
|
+
require 'bundler'
|
6
4
|
|
7
|
-
desc 'Default: run unit tests.'
|
8
|
-
task :default => :test
|
9
5
|
|
10
|
-
|
11
|
-
|
12
|
-
t.libs << 'lib'
|
13
|
-
t.pattern = 'test/**/*_test.rb'
|
14
|
-
t.verbose = true
|
15
|
-
end
|
6
|
+
# Run test by default.
|
7
|
+
task :default => :test
|
16
8
|
|
17
|
-
desc 'Generate documentation for the simpleconfig plugin.'
|
18
|
-
Rake::RDocTask.new(:rdoc) do |rdoc|
|
19
|
-
rdoc.rdoc_dir = 'rdoc'
|
20
|
-
rdoc.title = 'Simpleconfig'
|
21
|
-
rdoc.options << '--line-numbers' << '--inline-source'
|
22
|
-
rdoc.rdoc_files.include('README')
|
23
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
24
|
-
end
|
25
9
|
|
26
10
|
# This builds the actual gem. For details of what all these options
|
27
11
|
# mean, and other ones you can add, check the documentation here:
|
@@ -30,40 +14,23 @@ end
|
|
30
14
|
#
|
31
15
|
spec = Gem::Specification.new do |s|
|
32
16
|
s.name = "simpleconfig"
|
33
|
-
s.version = "1.
|
34
|
-
s.date = "2010-09-13"
|
17
|
+
s.version = "1.2.0"
|
35
18
|
s.summary = "Simple object-oriented application settings for Ruby applications"
|
36
|
-
s.email = "luke@lukeredpath.co.uk"
|
37
|
-
s.homepage = "http://github.com/lukeredpath/simpleconfig"
|
38
19
|
s.description = "SimpleConfig is a plugin designed to make application-wide configuration settings (e.g. in a Rails app) easy to set and access in an object-oriented fashion."
|
39
|
-
|
20
|
+
|
40
21
|
s.authors = ["Luke Redpath"]
|
41
|
-
s.
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
s.test_files = [
|
52
|
-
"test/controller_mixin_test.rb",
|
53
|
-
"test/network_host_test.rb",
|
54
|
-
"test/simple_config_functional_test.rb",
|
55
|
-
"test/simple_config_test.rb",
|
56
|
-
"test/yaml_parser_test.rb"
|
57
|
-
]
|
22
|
+
s.email = "luke@lukeredpath.co.uk"
|
23
|
+
s.homepage = "http://github.com/lukeredpath/simpleconfig"
|
24
|
+
|
25
|
+
s.files = `git ls-files`.split("\n")
|
26
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
27
|
+
s.require_paths = %w( lib )
|
28
|
+
|
29
|
+
s.add_development_dependency("rake")
|
30
|
+
s.add_development_dependency("yard")
|
31
|
+
s.add_development_dependency("mocha")
|
58
32
|
end
|
59
33
|
|
60
|
-
# This task actually builds the gem. We also regenerate a static
|
61
|
-
# .gemspec file, which is useful if something (i.e. GitHub) will
|
62
|
-
# be automatically building a gem for this project. If you're not
|
63
|
-
# using GitHub, edit as appropriate.
|
64
|
-
#
|
65
|
-
# To publish your gem online, install the 'gemcutter' gem; Read more
|
66
|
-
# about that here: http://gemcutter.org/pages/gem_docs
|
67
34
|
Gem::PackageTask.new(spec) do |pkg|
|
68
35
|
pkg.gem_spec = spec
|
69
36
|
end
|
@@ -74,16 +41,51 @@ task :gemspec do
|
|
74
41
|
File.open(file, "w") {|f| f << spec.to_ruby }
|
75
42
|
end
|
76
43
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
task :clean => [:clobber_rdoc, :clobber_package] do
|
81
|
-
rm "#{spec.name}.gemspec"
|
44
|
+
desc "Remove any temporary products, including gemspec"
|
45
|
+
task :clean => [:clobber] do
|
46
|
+
rm "#{spec.name}.gemspec" if File.file?("#{spec.name}.gemspec")
|
82
47
|
end
|
83
48
|
|
49
|
+
desc "Remove any generated file"
|
50
|
+
task :clobber => [:clobber_package]
|
51
|
+
|
52
|
+
desc "Package the library and generates the gemspec"
|
53
|
+
task :package => [:gemspec]
|
54
|
+
|
84
55
|
desc "Release to RubyGems.org"
|
85
56
|
task :release => :package do
|
86
57
|
system("gem push pkg/#{spec.file_name}") &&
|
87
58
|
system("git tag -a -m 'Tagged #{spec.version} release' v#{spec.version}") &&
|
88
59
|
system("git push --tags")
|
89
60
|
end
|
61
|
+
|
62
|
+
|
63
|
+
require 'rake/testtask'
|
64
|
+
|
65
|
+
Rake::TestTask.new do |t|
|
66
|
+
t.libs << "test"
|
67
|
+
t.test_files = FileList["test/**/*_test.rb"]
|
68
|
+
t.verbose = !!ENV["VERBOSE"]
|
69
|
+
t.warning = !!ENV["WARNING"]
|
70
|
+
end
|
71
|
+
|
72
|
+
|
73
|
+
require 'yard/rake/yardoc_task'
|
74
|
+
|
75
|
+
YARD::Rake::YardocTask.new(:yardoc) do |y|
|
76
|
+
y.options = ["--output-dir", "yardoc"]
|
77
|
+
end
|
78
|
+
|
79
|
+
namespace :yardoc do
|
80
|
+
task :clobber do
|
81
|
+
rm_r "yardoc" rescue nil
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
task :clobber => "yardoc:clobber"
|
86
|
+
|
87
|
+
|
88
|
+
desc "Open an irb session preloaded with this library"
|
89
|
+
task :console do
|
90
|
+
sh "irb -rubygems -I lib -r simple_config.rb"
|
91
|
+
end
|
data/lib/simple_config.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'yaml'
|
2
|
-
|
3
1
|
module SimpleConfig
|
4
2
|
|
5
3
|
class << self
|
@@ -25,11 +23,18 @@ module SimpleConfig
|
|
25
23
|
end
|
26
24
|
|
27
25
|
class Config
|
26
|
+
|
28
27
|
def initialize
|
29
|
-
@groups
|
28
|
+
@groups = {}
|
30
29
|
@settings = {}
|
31
30
|
end
|
32
31
|
|
32
|
+
def dup
|
33
|
+
self.class.new.tap do |duplicate|
|
34
|
+
duplicate.merge!(to_hash)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
33
38
|
def configure(&block)
|
34
39
|
instance_eval(&block)
|
35
40
|
end
|
@@ -51,7 +56,6 @@ module SimpleConfig
|
|
51
56
|
@settings[key]
|
52
57
|
end
|
53
58
|
|
54
|
-
#
|
55
59
|
# Unsets any variable with given +key+
|
56
60
|
# and returns variable value if it exists, nil otherwise.
|
57
61
|
# Any successive call to exists? :key will return false.
|
@@ -64,12 +68,13 @@ module SimpleConfig
|
|
64
68
|
# unset :bar # => 'foo'
|
65
69
|
# exists? :bar # => false
|
66
70
|
#
|
71
|
+
# @param [Symbol] The key to unset.
|
72
|
+
# @return The current value for +:key+.
|
67
73
|
def unset(key)
|
68
74
|
singleton_class.send(:remove_method, key)
|
69
75
|
@settings.delete(key)
|
70
76
|
end
|
71
77
|
|
72
|
-
#
|
73
78
|
# Returns whether a variable with given +key+ is set.
|
74
79
|
#
|
75
80
|
# Please note that this method doesn't care about variable value.
|
@@ -91,10 +96,16 @@ module SimpleConfig
|
|
91
96
|
# unset :bar
|
92
97
|
# exists? :bar # => false
|
93
98
|
#
|
99
|
+
# @param [Symbol] The key to check.
|
100
|
+
# @return [Boolean] True if the key is set.
|
94
101
|
def exists?(key)
|
95
102
|
@settings.key?(key)
|
96
103
|
end
|
97
104
|
|
105
|
+
def set?(key)
|
106
|
+
@settings.key?(key)
|
107
|
+
end
|
108
|
+
|
98
109
|
def to_hash
|
99
110
|
hash = @settings.dup
|
100
111
|
@groups.each do |key,group|
|
@@ -103,6 +114,21 @@ module SimpleConfig
|
|
103
114
|
hash
|
104
115
|
end
|
105
116
|
|
117
|
+
def merge!(hash)
|
118
|
+
hash.each do |key, value|
|
119
|
+
if value.is_a?(Hash)
|
120
|
+
group(key.to_sym).merge!(value)
|
121
|
+
else
|
122
|
+
set(key.to_sym, value)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
self
|
126
|
+
end
|
127
|
+
|
128
|
+
def merge(hash)
|
129
|
+
dup.merge!(hash)
|
130
|
+
end
|
131
|
+
|
106
132
|
def load(external_config_file, options={})
|
107
133
|
options = {:if_exists? => false}.merge(options)
|
108
134
|
|
@@ -118,24 +144,22 @@ module SimpleConfig
|
|
118
144
|
end
|
119
145
|
end
|
120
146
|
|
121
|
-
|
122
|
-
@settings.key?(key)
|
123
|
-
end
|
147
|
+
private
|
124
148
|
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
end
|
149
|
+
def define_accessor(name, &block)
|
150
|
+
singleton_class.class_eval { define_method(name, &block) } if !respond_to?(name) || exists?(name)
|
151
|
+
end
|
129
152
|
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
end
|
153
|
+
def singleton_class
|
154
|
+
class << self
|
155
|
+
self
|
134
156
|
end
|
157
|
+
end
|
135
158
|
end
|
136
159
|
|
137
160
|
class YAMLParser
|
138
161
|
def initialize(raw_yaml_data)
|
162
|
+
require 'yaml'
|
139
163
|
@data = YAML.load(raw_yaml_data)
|
140
164
|
end
|
141
165
|
|
@@ -144,20 +168,8 @@ module SimpleConfig
|
|
144
168
|
end
|
145
169
|
|
146
170
|
def parse_into(config)
|
147
|
-
@data
|
148
|
-
parse(key, value, config)
|
149
|
-
end
|
171
|
+
config.merge!(@data)
|
150
172
|
end
|
151
|
-
|
152
|
-
private
|
153
|
-
def parse(key, value, config)
|
154
|
-
if value.is_a?(Hash)
|
155
|
-
group = config.group(key.to_sym)
|
156
|
-
value.each { |key, value| parse(key, value, group) }
|
157
|
-
else
|
158
|
-
config.set(key.to_sym, value)
|
159
|
-
end
|
160
|
-
end
|
161
173
|
end
|
162
174
|
|
163
175
|
end
|
@@ -1,3 +1,9 @@
|
|
1
|
+
warn <<-EOS
|
2
|
+
DEPRECATION WARNING: SimpleConfig::ControllerMixin is deprecated and will be removed in SimpleConfig 2.0. If you really need this functionality, add the code to your app or consider creating a MicroGem.
|
3
|
+
See http://jeffkreeftmeijer.com/2011/microgems-five-minute-rubygems/
|
4
|
+
EOS
|
5
|
+
|
6
|
+
|
1
7
|
module SimpleConfig
|
2
8
|
module ControllerMixin
|
3
9
|
|
@@ -1,5 +1,10 @@
|
|
1
1
|
require 'uri'
|
2
2
|
|
3
|
+
warn <<-EOS
|
4
|
+
DEPRECATION WARNING: SimpleConfig::Utilities is deprecated and will be removed in SimpleConfig 2.0. Please package it as a Gem or MicroGem.
|
5
|
+
See http://jeffkreeftmeijer.com/2011/microgems-five-minute-rubygems/
|
6
|
+
EOS
|
7
|
+
|
3
8
|
module SimpleConfig
|
4
9
|
module Utilities
|
5
10
|
class NetworkHost
|
data/lib/simpleconfig.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'simple_config'
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = "simpleconfig"
|
5
|
+
s.version = "1.2.0"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Luke Redpath"]
|
9
|
+
s.date = "2012-06-27"
|
10
|
+
s.description = "SimpleConfig is a plugin designed to make application-wide configuration settings (e.g. in a Rails app) easy to set and access in an object-oriented fashion."
|
11
|
+
s.email = "luke@lukeredpath.co.uk"
|
12
|
+
s.files = [".gitignore", "CHANGELOG.md", "Gemfile", "MIT-LICENSE", "README.md", "Rakefile", "init.rb", "lib/simple_config.rb", "lib/simple_config/controller_mixin.rb", "lib/simple_config/utilities.rb", "lib/simpleconfig.rb", "lib/tasks/simple_config.rake", "simpleconfig.gemspec", "templates/configuration.rb", "test/controller_mixin_test.rb", "test/network_host_test.rb", "test/simple_config_functional_test.rb", "test/simple_config_test.rb", "test/test_helper.rb", "test/yaml_parser_test.rb"]
|
13
|
+
s.homepage = "http://github.com/lukeredpath/simpleconfig"
|
14
|
+
s.require_paths = ["lib"]
|
15
|
+
s.rubygems_version = "1.8.24"
|
16
|
+
s.summary = "Simple object-oriented application settings for Ruby applications"
|
17
|
+
s.test_files = ["test/controller_mixin_test.rb", "test/network_host_test.rb", "test/simple_config_functional_test.rb", "test/simple_config_test.rb", "test/test_helper.rb", "test/yaml_parser_test.rb"]
|
18
|
+
|
19
|
+
if s.respond_to? :specification_version then
|
20
|
+
s.specification_version = 3
|
21
|
+
|
22
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
23
|
+
s.add_development_dependency(%q<rake>, [">= 0"])
|
24
|
+
s.add_development_dependency(%q<yard>, [">= 0"])
|
25
|
+
s.add_development_dependency(%q<mocha>, [">= 0"])
|
26
|
+
else
|
27
|
+
s.add_dependency(%q<rake>, [">= 0"])
|
28
|
+
s.add_dependency(%q<yard>, [">= 0"])
|
29
|
+
s.add_dependency(%q<mocha>, [">= 0"])
|
30
|
+
end
|
31
|
+
else
|
32
|
+
s.add_dependency(%q<rake>, [">= 0"])
|
33
|
+
s.add_dependency(%q<yard>, [">= 0"])
|
34
|
+
s.add_dependency(%q<mocha>, [">= 0"])
|
35
|
+
end
|
36
|
+
end
|
data/test/network_host_test.rb
CHANGED
data/test/simple_config_test.rb
CHANGED
@@ -1,6 +1,4 @@
|
|
1
|
-
require
|
2
|
-
|
3
|
-
require 'simple_config'
|
1
|
+
require 'test_helper'
|
4
2
|
|
5
3
|
class SimpleConfigConfigTest < Test::Unit::TestCase
|
6
4
|
|
@@ -8,6 +6,21 @@ class SimpleConfigConfigTest < Test::Unit::TestCase
|
|
8
6
|
@config = SimpleConfig::Config.new
|
9
7
|
end
|
10
8
|
|
9
|
+
def test_dup_creates_deep_clone
|
10
|
+
new_config = cascaded_test_config.dup
|
11
|
+
new_config.configure do
|
12
|
+
group :test_group do
|
13
|
+
set :inner_key, 'new_foo'
|
14
|
+
end
|
15
|
+
set :test, 'new_test'
|
16
|
+
end
|
17
|
+
|
18
|
+
assert_equal 'test-setting', cascaded_test_config.test
|
19
|
+
assert_equal 'some other value', cascaded_test_config.test_group.inner_key
|
20
|
+
assert_equal 'new_test', new_config.test
|
21
|
+
assert_equal 'new_foo', new_config.test_group.inner_key
|
22
|
+
end
|
23
|
+
|
11
24
|
def test_should_be_able_to_set_config_values
|
12
25
|
@config.set(:var_one, 'hello world')
|
13
26
|
assert_equal 'hello world', @config.get(:var_one)
|
@@ -154,7 +167,26 @@ class SimpleConfigConfigTest < Test::Unit::TestCase
|
|
154
167
|
assert_equal "new-test-setting", @config.test
|
155
168
|
end
|
156
169
|
|
157
|
-
|
170
|
+
def test_config_merge_hash
|
171
|
+
config = SimpleConfig::Config.new
|
172
|
+
config.merge!(:example => {:foo => 'bar', :baz => 'qux'}, :test => 'foo')
|
173
|
+
|
174
|
+
assert_equal 'foo', config.test
|
175
|
+
assert_equal 'bar', config.example.foo
|
176
|
+
assert_equal 'qux', config.example.baz
|
177
|
+
end
|
178
|
+
|
179
|
+
def test_config_merge_hash_non_destructive
|
180
|
+
new_config = cascaded_test_config.merge(:test_group => {:inner_key => 'bar'}, :test => 'qux')
|
181
|
+
|
182
|
+
assert_equal 'test-setting', cascaded_test_config.test
|
183
|
+
assert_equal 'some other value', cascaded_test_config.test_group.inner_key
|
184
|
+
|
185
|
+
assert_equal 'qux', new_config.test
|
186
|
+
assert_equal 'bar', new_config.test_group.inner_key
|
187
|
+
end
|
188
|
+
|
189
|
+
private
|
158
190
|
|
159
191
|
def cascaded_test_config
|
160
192
|
SimpleConfig.for :simple_config_test do
|
data/test/test_helper.rb
ADDED
data/test/yaml_parser_test.rb
CHANGED
metadata
CHANGED
@@ -1,81 +1,122 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: simpleconfig
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.2.0
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 1
|
8
|
-
- 1
|
9
|
-
- 3
|
10
|
-
version: 1.1.3
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Luke Redpath
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
12
|
+
date: 2012-06-27 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: yard
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
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
|
47
|
+
name: mocha
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
description: SimpleConfig is a plugin designed to make application-wide configuration
|
63
|
+
settings (e.g. in a Rails app) easy to set and access in an object-oriented fashion.
|
22
64
|
email: luke@lukeredpath.co.uk
|
23
65
|
executables: []
|
24
|
-
|
25
66
|
extensions: []
|
26
|
-
|
27
67
|
extra_rdoc_files: []
|
28
|
-
|
29
|
-
|
68
|
+
files:
|
69
|
+
- .gitignore
|
70
|
+
- CHANGELOG.md
|
71
|
+
- Gemfile
|
72
|
+
- MIT-LICENSE
|
73
|
+
- README.md
|
74
|
+
- Rakefile
|
75
|
+
- init.rb
|
30
76
|
- lib/simple_config.rb
|
31
77
|
- lib/simple_config/controller_mixin.rb
|
32
78
|
- lib/simple_config/utilities.rb
|
79
|
+
- lib/simpleconfig.rb
|
33
80
|
- lib/tasks/simple_config.rake
|
34
|
-
-
|
35
|
-
- Rakefile
|
36
|
-
- README.textile
|
81
|
+
- simpleconfig.gemspec
|
37
82
|
- templates/configuration.rb
|
38
83
|
- test/controller_mixin_test.rb
|
39
84
|
- test/network_host_test.rb
|
40
85
|
- test/simple_config_functional_test.rb
|
41
86
|
- test/simple_config_test.rb
|
87
|
+
- test/test_helper.rb
|
42
88
|
- test/yaml_parser_test.rb
|
43
89
|
homepage: http://github.com/lukeredpath/simpleconfig
|
44
90
|
licenses: []
|
45
|
-
|
46
91
|
post_install_message:
|
47
92
|
rdoc_options: []
|
48
|
-
|
49
|
-
require_paths:
|
93
|
+
require_paths:
|
50
94
|
- lib
|
51
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
95
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
96
|
none: false
|
53
|
-
requirements:
|
54
|
-
- -
|
55
|
-
- !ruby/object:Gem::Version
|
56
|
-
|
57
|
-
segments:
|
97
|
+
requirements:
|
98
|
+
- - ! '>='
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
segments:
|
58
102
|
- 0
|
59
|
-
|
60
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
|
+
hash: -580664195664011592
|
104
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
105
|
none: false
|
62
|
-
requirements:
|
63
|
-
- -
|
64
|
-
- !ruby/object:Gem::Version
|
65
|
-
|
66
|
-
segments:
|
67
|
-
- 0
|
68
|
-
version: "0"
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
69
110
|
requirements: []
|
70
|
-
|
71
111
|
rubyforge_project:
|
72
|
-
rubygems_version: 1.8.
|
112
|
+
rubygems_version: 1.8.24
|
73
113
|
signing_key:
|
74
114
|
specification_version: 3
|
75
115
|
summary: Simple object-oriented application settings for Ruby applications
|
76
|
-
test_files:
|
116
|
+
test_files:
|
77
117
|
- test/controller_mixin_test.rb
|
78
118
|
- test/network_host_test.rb
|
79
119
|
- test/simple_config_functional_test.rb
|
80
120
|
- test/simple_config_test.rb
|
121
|
+
- test/test_helper.rb
|
81
122
|
- test/yaml_parser_test.rb
|