settings-tree 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +17 -16
- data/VERSION +1 -1
- data/lib/settings_tree/settings_holder.rb +10 -5
- data/settings-tree.gemspec +2 -2
- data/spec/settings_holder_spec.rb +2 -2
- metadata +15 -15
data/README.rdoc
CHANGED
@@ -8,8 +8,11 @@ The good things over similar gems is the ability to have deep, recursive structu
|
|
8
8
|
|
9
9
|
Example :
|
10
10
|
|
11
|
+
Settings.web_app.root_url => 'localhost:3000'
|
12
|
+
|
11
13
|
Settings.web_app.infos.company_name => 'Acme'
|
12
14
|
Settings.web_app.infos.app_name => 'Coffe maker'
|
15
|
+
|
13
16
|
Settings.web_app.engine.workers_count => 3
|
14
17
|
|
15
18
|
Those settings are read from a YAML file, like this one :
|
@@ -47,46 +50,44 @@ Those settings are read from a YAML file, like this one :
|
|
47
50
|
engine:
|
48
51
|
workers_count: 0
|
49
52
|
|
50
|
-
|
53
|
+
The common settings reside under a root named 'defaults'. Other roots ('production', 'development'...) will be picked depending on the environment. (more about that later)
|
51
54
|
|
52
|
-
This gem has more good features, keep reading
|
55
|
+
This gem has more good features, keep reading.
|
53
56
|
|
54
57
|
Ideas taken from : http://kpumuk.info/ruby-on-rails/flexible-application-configuration-in-ruby-on-rails/
|
55
58
|
|
56
59
|
== Installation
|
57
|
-
Available as a gem
|
60
|
+
Available as a gem in rubygems, the default gem repository :
|
58
61
|
gem 'settings-tree'
|
59
|
-
|
60
|
-
Isn't it easy ?
|
62
|
+
Isn't that easy ? (Thank you jeweler for making everything so easy)
|
61
63
|
|
62
64
|
== Use
|
63
65
|
|
64
66
|
You can uses several, independent 'groups'.
|
65
67
|
|
66
68
|
Just register a settings group from a file :
|
67
|
-
Settings.register_settings_file('web_app', File.join(File.dirname(__FILE__), "config/
|
69
|
+
Settings.register_settings_file('web_app', File.join(File.dirname(__FILE__), "config/config_web_app.yml"))
|
68
70
|
or for ruby on rails :
|
69
|
-
(in an initializer in config/initializer)
|
70
|
-
Settings.register_settings_file('web_app', File.join(::Rails.root.to_s, "config/
|
71
|
-
|
71
|
+
(put this line in an initializer in config/initializer)
|
72
|
+
Settings.register_settings_file('web_app', File.join(::Rails.root.to_s, "config/config_web_app.yml"))
|
72
73
|
Note : of course, the group name must be a valid keyword, able to be converted to a sym.
|
73
74
|
|
74
75
|
And now you can access your settings from anywhere :
|
75
|
-
|
76
|
+
Settings.web_app.infos.company_name => 'Acme'
|
76
77
|
(considering the YAML file given previously)
|
77
78
|
|
78
79
|
You can register any number of group you want :
|
79
|
-
Settings.register_settings_file('web_game', File.join(File.dirname(__FILE__), "config/
|
80
|
-
|
80
|
+
Settings.register_settings_file('web_game', File.join(File.dirname(__FILE__), "config/config_web_game.yml"))
|
81
|
+
example, with this file :
|
81
82
|
####### Common / default values #######
|
82
83
|
defaults:
|
83
84
|
guild_name: 'gang'
|
84
85
|
party_size: 4
|
85
|
-
|
86
|
+
gives :
|
86
87
|
puts Settings.web_game.guild_name => 'gang'
|
87
88
|
|
88
89
|
It's common to have settings that you don't want under version control (accounts, passwords).
|
89
|
-
A solution is to use a complementary file not under version control (gitignore). Just use :
|
90
|
+
A solution is to use a complementary file not under version control (thanks to a gitignore for example). Just use :
|
90
91
|
Settings.register_settings_file('web_app', File.join(File.dirname(__FILE__), "config/config_complement.yml"))
|
91
92
|
Since the 'web_app' group already exists, data will be merged, the new one taking precedence in case of conflicts. (Precedence is set according to the order of declaration.)
|
92
93
|
(All the source files are memorized, this is a complement, not a replacement.)
|
@@ -94,14 +95,14 @@ Since the 'web_app' group already exists, data will be merged, the new one takin
|
|
94
95
|
In case you want to reload the settings, you have two functions for that :
|
95
96
|
Settings.reload_all
|
96
97
|
Settings.reload_group('web_app')
|
97
|
-
(You may
|
98
|
+
(You may need that in development mode)
|
98
99
|
|
99
100
|
== Advanced use
|
100
101
|
Note : since those functions are rarely used, they don't have 'Settings.' shortcuts. Don't mind, it's the same.
|
101
102
|
=== Environment
|
102
103
|
In a rails app, the environment will be taken automatically from 'Rails.env'.
|
103
104
|
If not under a rails app or if the environment is not available, you may want to set it manually :
|
104
|
-
SettingsHolder.instance.
|
105
|
+
SettingsHolder.instance.set_environment('test')
|
105
106
|
(The existing files/groups will automatically be reloaded to take that into account.)
|
106
107
|
|
107
108
|
=== Reset
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.1
|
@@ -77,12 +77,17 @@ class SettingsHolder
|
|
77
77
|
end
|
78
78
|
end
|
79
79
|
|
80
|
-
|
80
|
+
# Set the environment to be used for conditional settings.
|
81
|
+
def set_environment(env)
|
81
82
|
@environment = env
|
82
83
|
|
83
84
|
# need to reload all
|
84
85
|
reload_all
|
85
86
|
end
|
87
|
+
# same same
|
88
|
+
def environment=(env)
|
89
|
+
set_environment(env)
|
90
|
+
end
|
86
91
|
|
87
92
|
def reload_all
|
88
93
|
@settings_list.each do |key, value|
|
@@ -182,16 +187,17 @@ class SettingsHolder
|
|
182
187
|
case src[:type]
|
183
188
|
when :file
|
184
189
|
begin
|
185
|
-
|
186
|
-
|
190
|
+
complete_config = YAML.load_file( src[:value] ) || {}
|
191
|
+
default_config = complete_config['defaults'] || {}
|
187
192
|
specialized_config = @environment.nil? ? {} : (complete_config[@environment] || {})
|
188
193
|
|
189
194
|
data = default_config.deep_merge(specialized_config)
|
190
195
|
rescue Errno::ENOENT => e
|
191
196
|
# no file, classic error.
|
192
|
-
# resend
|
197
|
+
# resend as is
|
193
198
|
raise e
|
194
199
|
rescue Exception => e
|
200
|
+
# unexpected error : add details.
|
195
201
|
#puts e.inspect
|
196
202
|
raise RuntimeError, "XXX There was a problem in parsing the file #{src[:value]}. Please investigate... #{e.message}"
|
197
203
|
end
|
@@ -202,5 +208,4 @@ class SettingsHolder
|
|
202
208
|
return data
|
203
209
|
end
|
204
210
|
|
205
|
-
|
206
211
|
end
|
data/settings-tree.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{settings-tree}
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = [%q{Offirmo}]
|
12
|
-
s.date = %q{2011-05-
|
12
|
+
s.date = %q{2011-05-31}
|
13
13
|
s.description = %q{This gem offers you a convenient settings structure for parameterizing your application.
|
14
14
|
Those settings are read from a YAML file.
|
15
15
|
Inheritance of settings (like in development modes) and multiple settings groups are available.
|
@@ -57,7 +57,7 @@ describe "SettingsHolder" do
|
|
57
57
|
SettingsHolder.instance.environment.should be_nil
|
58
58
|
SettingsHolder.instance.get_settings(:web_app).engine.auto_manage_workers_redirect_output.should == true
|
59
59
|
# change environment (settings are automatically reloaded)
|
60
|
-
SettingsHolder.instance.
|
60
|
+
SettingsHolder.instance.set_environment('development')
|
61
61
|
# after
|
62
62
|
SettingsHolder.instance.environment.should == 'development'
|
63
63
|
SettingsHolder.instance.get_settings(:web_app).engine.auto_manage_workers_redirect_output.should == false
|
@@ -68,7 +68,7 @@ describe "SettingsHolder" do
|
|
68
68
|
SettingsHolder.instance.get_settings(:web_app).engine.auto_manage_workers_redirect_output.should == false
|
69
69
|
SettingsHolder.instance.get_settings(:web_app).engine.workers_count.should == 3
|
70
70
|
# change environment (settings are automatically reloaded)
|
71
|
-
SettingsHolder.instance.
|
71
|
+
SettingsHolder.instance.set_environment('test')
|
72
72
|
# after
|
73
73
|
SettingsHolder.instance.environment.should == 'test'
|
74
74
|
SettingsHolder.instance.get_settings(:web_app).engine.auto_manage_workers_redirect_output.should == true
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: settings-tree
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-05-
|
12
|
+
date: 2011-05-31 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: recursive-open-struct
|
16
|
-
requirement: &
|
16
|
+
requirement: &86541720 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *86541720
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: hash-deep-merge
|
27
|
-
requirement: &
|
27
|
+
requirement: &86541480 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *86541480
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rspec
|
38
|
-
requirement: &
|
38
|
+
requirement: &86541240 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *86541240
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: bundler
|
49
|
-
requirement: &
|
49
|
+
requirement: &86540980 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *86540980
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: jeweler
|
60
|
-
requirement: &
|
60
|
+
requirement: &86540740 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *86540740
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rcov
|
71
|
-
requirement: &
|
71
|
+
requirement: &86540500 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,7 +76,7 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *86540500
|
80
80
|
description: ! 'This gem offers you a convenient settings structure for parameterizing
|
81
81
|
your application.
|
82
82
|
|
@@ -127,7 +127,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
127
127
|
version: '0'
|
128
128
|
segments:
|
129
129
|
- 0
|
130
|
-
hash:
|
130
|
+
hash: -827487391
|
131
131
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
132
132
|
none: false
|
133
133
|
requirements:
|