settings-tree 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -10,7 +10,7 @@ GEM
10
10
  rake
11
11
  rake (0.9.0)
12
12
  rcov (0.9.9)
13
- recursive-open-struct (0.1.0)
13
+ recursive-open-struct (0.2.0)
14
14
  rspec (2.6.0)
15
15
  rspec-core (~> 2.6.0)
16
16
  rspec-expectations (~> 2.6.0)
@@ -15,7 +15,7 @@ Example :
15
15
  Those settings are read from a YAML file, like this one :
16
16
 
17
17
  # YAML private config file
18
- # XXX Beware ! This YAML : indention with spaces only ! XXX
18
+ # XXX Beware ! This is YAML : indention with spaces only ! XXX
19
19
 
20
20
  ####### Common / default values #######
21
21
  defaults:
@@ -60,40 +60,58 @@ Available as a gem
60
60
  Isn't it easy ?
61
61
 
62
62
  == Use
63
+
64
+ You can uses several, independent 'groups'.
65
+
63
66
  Just register a settings group from a file :
64
67
  Settings.register_settings_file('web_app', File.join(File.dirname(__FILE__), "config/config.yml"))
65
68
  or for ruby on rails :
69
+ (in an initializer in config/initializer)
66
70
  Settings.register_settings_file('web_app', File.join(::Rails.root.to_s, "config/config.yml"))
67
71
 
72
+ Note : of course, the group name must be a valid keyword, able to be converted to a sym.
73
+
68
74
  And now you can access your settings from anywhere :
69
75
  puts Settings.web_app.infos.company_name
70
-
71
- Note : of course, the group name must be a valid keyword, able to be converted to a sym.
76
+ (considering the YAML file given previously)
72
77
 
73
78
  You can register any number of group you want :
74
79
  Settings.register_settings_file('web_game', File.join(File.dirname(__FILE__), "config/another_config.yml"))
75
- And then :
76
- puts Settings.web_game.guild_name.should == 'gang'
80
+ for this file :
81
+ ####### Common / default values #######
82
+ defaults:
83
+ guild_name: 'gang'
84
+ party_size: 4
85
+ Giving :
86
+ puts Settings.web_game.guild_name => 'gang'
77
87
 
78
- It's common to have settings that you don't want to stay under version control (accounts, passwords).
79
- A solution is to use a complementary file not under version control. Just use :
88
+ 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 :
80
90
  Settings.register_settings_file('web_app', File.join(File.dirname(__FILE__), "config/config_complement.yml"))
81
- And data will be merged, the new one taking precedence in case of conflicts.
91
+ 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
+ (All the source files are memorized, this is a complement, not a replacement.)
82
93
 
83
94
  In case you want to reload the settings, you have two functions for that :
84
95
  Settings.reload_all
85
96
  Settings.reload_group('web_app')
97
+ (You may want to do that in development mode)
86
98
 
87
99
  == Advanced use
88
100
  Note : since those functions are rarely used, they don't have 'Settings.' shortcuts. Don't mind, it's the same.
89
101
  === Environment
90
- In a rails app, the environment will be taken automatically from 'Rails.env'. If not under a rails app or if the environment is not available, set it manually :
102
+ In a rails app, the environment will be taken automatically from 'Rails.env'.
103
+ If not under a rails app or if the environment is not available, you may want to set it manually :
91
104
  SettingsHolder.instance.environment = 'test'
92
- The files will automatically be reloaded to take that into account.
105
+ (The existing files/groups will automatically be reloaded to take that into account.)
93
106
 
107
+ === Reset
94
108
  You may also want to reset all the settings (everything will be forgotten) :
95
109
  SettingsHolder.instance.reset
96
-
110
+
111
+ === Debug
112
+ A convenient debug function to see all the settings and their values :
113
+ SettingsHolder.instance.debug_inspect
114
+
97
115
  == Contributing to settings-tree
98
116
 
99
117
  * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.2.0
@@ -31,7 +31,18 @@ class SettingsHolder
31
31
  initialize
32
32
  end
33
33
 
34
- #
34
+ # a convenience function which displays the datas
35
+ def debug_inspect
36
+ puts "*** Current settings :"
37
+ #puts @settings_list.inspect
38
+ @settings_list.each do |key, value|
39
+ puts "Settings.#{key}."
40
+ @settings_list[key][:data].debug_inspect(1)
41
+ end
42
+ end
43
+
44
+ # Register a source file for a group.
45
+ # The group will be created if not already existing.
35
46
  def register_settings_file(name, file)
36
47
 
37
48
  group_just_created = false
@@ -55,6 +66,7 @@ class SettingsHolder
55
66
  return res
56
67
  end
57
68
 
69
+ # Return this group of settings as an openstruct
58
70
  def get_settings(name)
59
71
  #puts name.inspect
60
72
  #puts @settings_list.inspect
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{settings-tree}
8
- s.version = "0.1.1"
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 = [%q{Offirmo}]
@@ -28,6 +28,9 @@ describe "SettingsHolder" do
28
28
  end
29
29
 
30
30
  it "should load all settings" do
31
+
32
+ SettingsHolder.instance.debug_inspect
33
+
31
34
  # and now let's query all the expected settings
32
35
  SettingsHolder.instance.get_settings(:web_app).root_url.should == 'localhost:3000'
33
36
  SettingsHolder.instance.get_settings(:web_app).public_access.should be_true
@@ -1,7 +1,7 @@
1
1
  # YAML private config file
2
2
  # http://kpumuk.info/ruby-on-rails/flexible-application-configuration-in-ruby-on-rails/
3
3
 
4
- # XXX Beware ! This YAML : indention with spaces only ! XXX
4
+ # XXX Beware ! This is YAML : indention with spaces only ! XXX
5
5
 
6
6
 
7
7
  ####### Common / default values #######
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.1.1
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2011-05-25 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: recursive-open-struct
16
- requirement: &79882210 !ruby/object:Gem::Requirement
16
+ requirement: &88517810 !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: *79882210
24
+ version_requirements: *88517810
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: hash-deep-merge
27
- requirement: &79881970 !ruby/object:Gem::Requirement
27
+ requirement: &88517570 !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: *79881970
35
+ version_requirements: *88517570
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec
38
- requirement: &79881730 !ruby/object:Gem::Requirement
38
+ requirement: &88517310 !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: *79881730
46
+ version_requirements: *88517310
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: bundler
49
- requirement: &79881490 !ruby/object:Gem::Requirement
49
+ requirement: &88517070 !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: *79881490
57
+ version_requirements: *88517070
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: jeweler
60
- requirement: &79881250 !ruby/object:Gem::Requirement
60
+ requirement: &88516830 !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: *79881250
68
+ version_requirements: *88516830
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rcov
71
- requirement: &79881010 !ruby/object:Gem::Requirement
71
+ requirement: &88516570 !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: *79881010
79
+ version_requirements: *88516570
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: 228111425
130
+ hash: 370010543
131
131
  required_rubygems_version: !ruby/object:Gem::Requirement
132
132
  none: false
133
133
  requirements: