dynamic_configuration 0.1.6 → 0.2.0

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/README.markdown CHANGED
@@ -1,4 +1,4 @@
1
- # dynamic_configuration: Application configuration made easy
1
+ # dynamic_configuration
2
2
 
3
3
  Rails made great innovations in almost all areas of web application
4
4
  development, yet it surprisingly does not provide any means for
@@ -10,48 +10,168 @@ differentiate dynamic_configuration from other configuration plugins:
10
10
 
11
11
  * configuration files are very clean-looking Ruby files
12
12
 
13
- * the configuration is automatically reloaded in Rails development environment
13
+ * in Rails development environment, one doesn't have to restart the
14
+ server to add/remove/modify a setting
14
15
 
15
- * the settings are divided into groups, with each group living in a
16
+ * the settings are divided into groups, each group being defined in a
16
17
  separate file, making it easier to remember individual setting
17
18
  names and maintain the whole configuration
18
19
 
19
- * settings can be overridden locally for a given installation and
20
- per-Rails-environment
20
+ * settings can be overridden per-Rails-environment and locally for a
21
+ given installation (useful for customizing the configuration
22
+ per-server, while keeping the core settings in Git)
21
23
 
22
24
  * throughout field- and unit- tested
23
25
 
26
+ Developed as part of my work for http://www.tutoria.de/.
27
+
24
28
  ## Setup
25
29
 
26
30
  ### Rails 3 application:
27
31
 
28
32
  Add the gem to your Gemfile:
29
33
 
30
- gem 'dynamic_configuration'
34
+ ```ruby
35
+ gem 'dynamic_configuration'
36
+ ```
31
37
 
32
- Create a config/options directory, in it a config/options.rb file with
33
- the following contents:
38
+ Create a config/options directory, then a config/options/options.rb
39
+ file with the following contents:
34
40
 
35
- DynamicConfiguration::create(:Options, File.join(Rails.root, "config/options"))
41
+ ```ruby
42
+ DynamicConfiguration::create(:Options, File.join(Rails.root, "config/options"))
43
+ ```
36
44
 
37
45
  Require config/options/options.rb somewhere in your
38
46
  config/application.rb, like this:
39
47
 
40
- module SomeApplication
41
- class Application < Rails::Application
42
- require "config/options/options"
48
+ ```ruby
49
+ module SomeApplication
50
+ class Application < Rails::Application
51
+ require "config/options/options"
43
52
 
44
- # ..., rest of the config
45
- end
46
- end
53
+ # ..., rest of the config
54
+ end
55
+ end
56
+ ```
47
57
 
48
58
  ### Ruby application:
49
59
 
50
- Create a directory where you want to store the options, e. g.
51
- options/, and put the following before your application initialization
52
- code:
53
-
54
- DynamicConfiguration::create(:Options, "/path/to/options")
60
+ Create a subdirectory of your project directory where you want to
61
+ store the options, e. g. options/, and put the following before your
62
+ application initialization code:
55
63
 
64
+ ```ruby
65
+ DynamicConfiguration::create(:Options, "options/")
66
+ ```
56
67
 
57
68
  ## Usage
69
+
70
+ ### Basics
71
+
72
+ You create a settings group by creating a file somewhere in the
73
+ options directory, to see how it works, create options/main.rb and
74
+ define a single setting in it:
75
+
76
+ ```ruby
77
+ # config/options/main.rb
78
+ a_string "sample value"
79
+ ```
80
+
81
+ This will make Options.main.a_string evaluate to "sample value"
82
+ anywhere in your application:
83
+
84
+ ```ruby
85
+ Options.main.a_string
86
+ => "sample value"
87
+ ```
88
+
89
+ The name of the group of options is set to be the same as the base
90
+ name of the file, so if you create emails.rb, the settings will be
91
+ accessible as Options.emails.whatever_you_define etc.
92
+
93
+ The value of each settings can be any kind of Ruby object, so the
94
+ following is a valid config file:
95
+
96
+ ```ruby
97
+ # config/options/main.rb
98
+ a_string "Some string"
99
+
100
+ an_array [1, 2, 3]
101
+
102
+ a_fancy_string_array(%w{
103
+ string1
104
+ string2
105
+ })
106
+ ```
107
+
108
+ Which you can use in other places of your application like this:
109
+
110
+ ```ruby
111
+ Options.main.a_string
112
+ => "Some string"
113
+ Options.main.an_array
114
+ => [1, 2, 3]
115
+ Options.main.a_fancy_string_array
116
+ => ["string1", "string2"]
117
+ ```
118
+
119
+ Note that hash map values have to be wrapped in parenthesis, since
120
+ defining a setting works under the hood as a Ruby method call, so it
121
+ has to have the syntax of one.
122
+
123
+ ### Overriding settings per Rails environment ###
124
+
125
+ To overwrite the settings for a given Rails environment, just create a
126
+ subdirectory of the options directory named after the name of the
127
+ environment, for example config/options/test/. Then create a file
128
+ corresponding to the group of settings of which one or more you want
129
+ to override. For example, if config/options/main.rb looks like above,
130
+ and you create config/options/test/main.rb looking like this:
131
+
132
+ ```ruby
133
+ # config/options/test/main.rb
134
+ a_string "Test"
135
+ ```
136
+
137
+ Then Options.main.a_string will evaluate to "Test" in the test
138
+ environment, while all the other Options.main settings will evaluate
139
+ to their values defined in config/options/main.rb.
140
+
141
+ ### Overriding settings locally ###
142
+
143
+ This is mostly meant for applications that are stored in a version
144
+ control system and on which multiple persons work. One can keep the
145
+ core settings in config/options, and also create a
146
+ config/options/local directory, that can be svn ignore'd or added to
147
+ .gitignore. If then someone wants to override some setting just on a
148
+ particular server or just on his local development environment, he/she
149
+ can create a file corresponding to the group of settings of which one
150
+ or more he/she wants to override, for example
151
+ config/options/local/main.rb:
152
+
153
+ ```ruby
154
+ # config/options/local/main.rb
155
+ an_array [4, 5, 6]
156
+ ```
157
+
158
+ Then, Options.main.an_array will evaluate to [4, 5, 6] regardless of
159
+ Rails environment and other Options.main settings will be evaluated
160
+ according to their per-Rails-environment definitions if present, or
161
+ according to their global definitions in config/options/main.rb
162
+ otherwise.
163
+
164
+ ## Robustness ##
165
+
166
+ dynamic_configuration overwrites method_missing in the context of the
167
+ configuration files to enable the syntax it provides. It doesn't do
168
+ anything to method_missing globally, nor does it do any other "magic"
169
+ that could affect any piece of your application other then the
170
+ configuration files themselves.
171
+
172
+ All the settings are frozen as soon as they are defined, so you won't
173
+ accidentally modify them. If you try to access a settings group that
174
+ wasn't defined, you will get an
175
+ DynamicConfiguration::MissingGroupException, if you try to access a
176
+ setting that isn't defined of a group that _is_ defined, you will get
177
+ a DynamicConfiguration::MissingGroupException.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.6
1
+ 0.2.0
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{dynamic_configuration}
8
- s.version = "0.1.6"
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{Jarosław Rzeszótko}]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dynamic_configuration
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-01-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: builder
16
- requirement: &81569210 !ruby/object:Gem::Requirement
16
+ requirement: &76717450 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *81569210
24
+ version_requirements: *76717450
25
25
  description: Flexible configuration library for Ruby and Rails applications.
26
26
  email: jrzeszotko@gmail.com
27
27
  executables: []