dynamic_configuration 0.3.14 → 0.3.15

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 425ae95c29d5bd5d332340549b603a14bc7763bb
4
- data.tar.gz: e7238415edef3f48da4bc43137f2e543cee1823c
3
+ metadata.gz: a193f927145ad061e46c013dbcf8d9f038733764
4
+ data.tar.gz: d3d1bfd51da8f1755ef4c2b070446ed0f27c2f69
5
5
  SHA512:
6
- metadata.gz: d9536a059603c8568aff1c5c62ba84b24c7e6480733104e409c605ddd0cf8a2588e6386f147ee6fff0efef0bc738993955d12dad6446d294169dae19fa04ef18
7
- data.tar.gz: 59e496dc3da5fab5eee01485e8a24d574b71386c1f2d637ca8c4ac193f92479dc099f5beb73faef68d908ede187adc3c78165506a4dd0bc4a7ddcabf57b44d6c
6
+ metadata.gz: 914b381b462dce73c78a7e6725d4aed48ffe52ca7b41b08857fce77e189fc85c2d162fc79856a74c745b6bbb8a7f55923e52114170715be13af625a2ceaeef67
7
+ data.tar.gz: f3bbb87ec54521bb03df00f16589f02fc638f3e020b6efe843de86d9485d290c6038f2395e526c4a6dd404608b4d6a0d57642a49a67b4845658b760265439f17
data/README CHANGED
@@ -1,25 +1,24 @@
1
1
  # dynamic_configuration
2
2
 
3
- Rails made great innovations in almost all areas of web application
4
- development, yet it surprisingly does not provide any means for
5
- application configuration, and each of the so far available plugins I
6
- have seen had some serious disadvantages. Here are the features that
7
- differentiate dynamic_configuration from other configuration plugins:
3
+ Dynamic_configuration is a library for storing application settings,
4
+ with the following distinguishing characteristics:
8
5
 
9
- * very easy setup with only two lines of code
6
+ * very easy setup with only one line of code
10
7
 
11
- * configuration files are very clean-looking Ruby files
8
+ * setting files are neat-looking Ruby files, with all of Ruby
9
+ available for specifying the setting values
12
10
 
13
- * in Rails development environment, one doesn't have to restart the
14
- server to add/remove/modify a setting
11
+ * settings are divided into groups, each group defined in a separate
12
+ file, making it easier to remember individual setting names and
13
+ maintain the whole configuration
15
14
 
16
- * the settings are divided into groups, each group being defined in a
17
- separate file, making it easier to remember individual setting
18
- names and maintain the whole configuration
15
+ * settings can be overridden locally for a given installation (useful
16
+ for customizing webapp configuration per-server, while keeping
17
+ default developer settings in Git)
19
18
 
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)
19
+ * Rails-friendly, for example settings can be overwritten
20
+ per-Rails-environment, they are also automatically reloaded on
21
+ every request in Rails development environment
23
22
 
24
23
  * throughout field- and unit- tested
25
24
 
@@ -27,61 +26,42 @@ Developed as part of my work for http://www.tutoria.de/.
27
26
 
28
27
  ## Setup
29
28
 
30
- ### Rails 3 application:
29
+ After adding dynamic_configuration to your Gemfile, or installing and
30
+ requiring it in your code manually, create a root directory for the
31
+ settings, for example config/opts, and then in it a
32
+ config/opts/opts.rb file with the following contents:
31
33
 
32
- Add the gem to your Gemfile:
34
+ DynamicConfiguration::create(:Opts, __FILE__)
33
35
 
34
- gem 'dynamic_configuration'
35
-
36
- Create a config/options directory, then a config/options/options.rb
37
- file with the following contents:
38
-
39
- DynamicConfiguration::create(:Options, File.join(Rails.root, "config/options"))
40
-
41
- Require config/options/options.rb somewhere in your
42
- config/application.rb, like this:
43
-
44
- module SomeApplication
45
- class Application < Rails::Application
46
- require "config/options/options"
47
-
48
- # ..., rest of the config
49
- end
50
- end
51
-
52
- ### Ruby application:
53
-
54
- Create a subdirectory of your project directory where you want to
55
- store the options, e. g. options/, and put the following before your
56
- application initialization code:
57
-
58
- DynamicConfiguration::create(:Options, "options/")
36
+ Once you require this file somewhere in your application, the constant
37
+ Opts will hold all the settings.
59
38
 
60
39
  ## Usage
61
40
 
62
41
  ### Basics
63
42
 
64
- You create a settings group by creating a file somewhere in the
65
- options directory, to see how it works, create options/main.rb and
66
- define a single setting in it:
43
+ You create a settings group by creating a file somewhere in the opts
44
+ directory, for example opts/main.rb, and defining some settings in it,
45
+ using Ruby method call syntax and semantics, but with the name of the
46
+ setting taking the place of the method name:
67
47
 
68
- # config/options/main.rb
69
- a_string "sample value"
48
+ # config/opts/main.rb
49
+ owner_email "john@doe.com"
70
50
 
71
- This will make Options.main.a_string evaluate to "sample value"
72
- anywhere in your application:
51
+ This will make Opts.main.a_string evaluate to "sample value" anywhere
52
+ in your application:
73
53
 
74
- Options.main.a_string
75
- => "sample value"
54
+ Opts.main.owner_email
55
+ => "john@doe.com"
76
56
 
77
- The name of the group of options is set to be the same as the base
78
- name of the file, so if you create emails.rb, the settings will be
79
- accessible as Options.emails.whatever_you_define etc.
57
+ The name of the group of opts is set to be the same as the base name
58
+ of the file, so if you create emails.rb, the settings will be
59
+ accessible as Opts.emails.whatever_you_define etc.
80
60
 
81
61
  The value of each settings can be any kind of Ruby object, so the
82
62
  following is a valid config file:
83
63
 
84
- # config/options/main.rb
64
+ # config/opts/main.rb
85
65
  a_string "Some string"
86
66
 
87
67
  an_array [1, 2, 3]
@@ -93,11 +73,11 @@ following is a valid config file:
93
73
 
94
74
  Which you can use in other places of your application like this:
95
75
 
96
- Options.main.a_string
76
+ Opts.main.a_string
97
77
  => "Some string"
98
- Options.main.an_array
78
+ Opts.main.an_array
99
79
  => [1, 2, 3]
100
- Options.main.a_fancy_string_array
80
+ Opts.main.a_fancy_string_array
101
81
  => ["string1", "string2"]
102
82
 
103
83
  Note that hash map values have to be wrapped in parenthesis, since
@@ -107,40 +87,56 @@ has to have the syntax of one.
107
87
  ### Overriding settings per Rails environment ###
108
88
 
109
89
  To overwrite the settings for a given Rails environment, just create a
110
- subdirectory of the options directory named after the name of the
111
- environment, for example config/options/test/. Then create a file
90
+ subdirectory of the opts directory named after the name of the
91
+ environment, for example config/opts/test/. Then create a file
112
92
  corresponding to the group of settings of which one or more you want
113
- to override. For example, if config/options/main.rb looks like above,
114
- and you create config/options/test/main.rb looking like this:
93
+ to override. For example, if config/opts/main.rb looks like above, and
94
+ you create config/opts/test/main.rb looking like this:
115
95
 
116
- # config/options/test/main.rb
96
+ # config/opts/test/main.rb
117
97
  a_string "Test"
118
98
 
119
- Then Options.main.a_string will evaluate to "Test" in the test
120
- environment, while all the other Options.main settings will evaluate
121
- to their values defined in config/options/main.rb.
99
+ Then Opts.main.a_string will evaluate to "Test" in the test
100
+ environment, while all the other Opts.main settings will evaluate to
101
+ their values defined in config/opts/main.rb.
122
102
 
123
103
  ### Overriding settings locally ###
124
104
 
125
105
  This is mostly meant for applications that are stored in a version
126
106
  control system and on which multiple persons work. One can keep the
127
- core settings in config/options, and also create a
128
- config/options/local directory, that can be svn ignore'd or added to
129
- .gitignore. If then someone wants to override some setting just on a
130
- particular server or just on his local development environment, he/she
131
- can create a file corresponding to the group of settings of which one
132
- or more he/she wants to override, for example
133
- config/options/local/main.rb:
134
-
135
- # config/options/local/main.rb
107
+ default settings in config/opts, and also create a config/opts/local
108
+ directory, that can be ignored in version control. If then someone
109
+ wants to override some setting just on a particular server or just on
110
+ his local development environment, he/she can create a file
111
+ corresponding to the group of settings of which one or more he/she
112
+ wants to override, for example config/opts/local/main.rb:
113
+
114
+ # config/opts/local/main.rb
136
115
  an_array [4, 5, 6]
137
116
 
138
- Then, Options.main.an_array will evaluate to [4, 5, 6] regardless of
139
- Rails environment and other Options.main settings will be evaluated
117
+ Then, Opts.main.an_array will evaluate to [4, 5, 6] regardless of
118
+ Rails environment and other Opts.main settings will be evaluated
140
119
  according to their per-Rails-environment definitions if present, or
141
- according to their global definitions in config/options/main.rb
120
+ according to their global definitions in config/opts/main.rb
142
121
  otherwise.
143
122
 
123
+ ## Tips ##
124
+
125
+ 1. Many more obvious constant names like Options, or Config, are names
126
+ of Ruby or Rails classes, and will cause name clashes in certain
127
+ contexts. Hence the examples use less neat but reliable Opts name.
128
+
129
+ 2. You can make the options available much earlier in the Rails
130
+ loading process by explicitly requiring them in config/application.rb:
131
+
132
+ module SomeApplication
133
+ class Application < Rails::Application
134
+ require "config/opts/opts"
135
+
136
+ # ..., rest of the config
137
+ end
138
+ end
139
+
144
140
  ## Robustness ##
145
141
 
146
142
  dynamic_configuration overwrites method_missing in the context of the
data/README.markdown CHANGED
@@ -1,25 +1,24 @@
1
1
  # dynamic_configuration
2
2
 
3
- Rails made great innovations in almost all areas of web application
4
- development, yet it surprisingly does not provide any means for
5
- application configuration, and each of the so far available plugins I
6
- have seen had some serious disadvantages. Here are the features that
7
- differentiate dynamic_configuration from other configuration plugins:
3
+ Dynamic_configuration is a library for storing application settings,
4
+ with the following distinguishing characteristics:
8
5
 
9
- * very easy setup with only two lines of code
6
+ * very easy setup with only one line of code
10
7
 
11
- * configuration files are very clean-looking Ruby files
8
+ * setting files are neat-looking Ruby files, with all of Ruby
9
+ available for specifying the setting values
12
10
 
13
- * in Rails development environment, one doesn't have to restart the
14
- server to add/remove/modify a setting
11
+ * settings are divided into groups, each group defined in a separate
12
+ file, making it easier to remember individual setting names and
13
+ maintain the whole configuration
15
14
 
16
- * the settings are divided into groups, each group being defined in a
17
- separate file, making it easier to remember individual setting
18
- names and maintain the whole configuration
15
+ * settings can be overridden locally for a given installation (useful
16
+ for customizing webapp configuration per-server, while keeping
17
+ default developer settings in Git)
19
18
 
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)
19
+ * Rails-friendly, for example settings can be overwritten
20
+ per-Rails-environment, they are also automatically reloaded on
21
+ every request in Rails development environment
23
22
 
24
23
  * throughout field- and unit- tested
25
24
 
@@ -27,78 +26,53 @@ Developed as part of my work for http://www.tutoria.de/.
27
26
 
28
27
  ## Setup
29
28
 
30
- ### Rails 3 application:
31
-
32
- Add the gem to your Gemfile:
33
-
34
- ```ruby
35
- gem 'dynamic_configuration'
36
- ```
37
-
38
- Create a config/options directory, then a config/options/options.rb
39
- file with the following contents:
40
-
41
- ```ruby
42
- DynamicConfiguration::create(:Options, File.join(Rails.root, "config/options"))
43
- ```
44
-
45
- Require config/options/options.rb somewhere in your
46
- config/application.rb, like this:
29
+ After adding dynamic_configuration to your Gemfile, or installing and
30
+ requiring it in your code manually, create a root directory for the
31
+ settings, for example config/opts, and then in it a
32
+ config/opts/opts.rb file with the following contents:
47
33
 
48
34
  ```ruby
49
- module SomeApplication
50
- class Application < Rails::Application
51
- require "config/options/options"
52
-
53
- # ..., rest of the config
54
- end
55
- end
35
+ DynamicConfiguration::create(:Opts, __FILE__)
56
36
  ```
57
37
 
58
- ### Ruby application:
59
-
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:
63
-
64
- ```ruby
65
- DynamicConfiguration::create(:Options, "options/")
66
- ```
38
+ Once you require this file somewhere in your application, the constant
39
+ Opts will hold all the settings.
67
40
 
68
41
  ## Usage
69
42
 
70
43
  ### Basics
71
44
 
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:
45
+ You create a settings group by creating a file somewhere in the opts
46
+ directory, for example opts/main.rb, and defining some settings in it,
47
+ using Ruby method call syntax and semantics, but with the name of the
48
+ setting taking the place of the method name:
75
49
 
76
50
  ```ruby
77
- # config/options/main.rb
78
- a_string "sample value"
51
+ # config/opts/main.rb
52
+ owner_email "john@doe.com"
79
53
  ```
80
54
 
81
- This will make Options.main.a_string evaluate to "sample value"
82
- anywhere in your application:
55
+ This will make Opts.main.a_string evaluate to "sample value" anywhere
56
+ in your application:
83
57
 
84
58
  ```ruby
85
- Options.main.a_string
86
- => "sample value"
59
+ Opts.main.owner_email
60
+ => "john@doe.com"
87
61
  ```
88
62
 
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.
63
+ The name of the group of opts is set to be the same as the base name
64
+ of the file, so if you create emails.rb, the settings will be
65
+ accessible as Opts.emails.whatever_you_define etc.
92
66
 
93
67
  The value of each settings can be any kind of Ruby object, so the
94
68
  following is a valid config file:
95
69
 
96
70
  ```ruby
97
- # config/options/main.rb
71
+ # config/opts/main.rb
98
72
  a_string "Some string"
99
-
73
+
100
74
  an_array [1, 2, 3]
101
-
75
+
102
76
  a_fancy_string_array(%w{
103
77
  string1
104
78
  string2
@@ -108,11 +82,11 @@ string2
108
82
  Which you can use in other places of your application like this:
109
83
 
110
84
  ```ruby
111
- Options.main.a_string
85
+ Opts.main.a_string
112
86
  => "Some string"
113
- Options.main.an_array
87
+ Opts.main.an_array
114
88
  => [1, 2, 3]
115
- Options.main.a_fancy_string_array
89
+ Opts.main.a_fancy_string_array
116
90
  => ["string1", "string2"]
117
91
  ```
118
92
 
@@ -123,44 +97,62 @@ has to have the syntax of one.
123
97
  ### Overriding settings per Rails environment ###
124
98
 
125
99
  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
100
+ subdirectory of the opts directory named after the name of the
101
+ environment, for example config/opts/test/. Then create a file
128
102
  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:
103
+ to override. For example, if config/opts/main.rb looks like above, and
104
+ you create config/opts/test/main.rb looking like this:
131
105
 
132
106
  ```ruby
133
- # config/options/test/main.rb
107
+ # config/opts/test/main.rb
134
108
  a_string "Test"
135
109
  ```
136
110
 
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.
111
+ Then Opts.main.a_string will evaluate to "Test" in the test
112
+ environment, while all the other Opts.main settings will evaluate to
113
+ their values defined in config/opts/main.rb.
140
114
 
141
115
  ### Overriding settings locally ###
142
116
 
143
117
  This is mostly meant for applications that are stored in a version
144
118
  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:
119
+ default settings in config/opts, and also create a config/opts/local
120
+ directory, that can be ignored in version control. If then someone
121
+ wants to override some setting just on a particular server or just on
122
+ his local development environment, he/she can create a file
123
+ corresponding to the group of settings of which one or more he/she
124
+ wants to override, for example config/opts/local/main.rb:
152
125
 
153
126
  ```ruby
154
- # config/options/local/main.rb
127
+ # config/opts/local/main.rb
155
128
  an_array [4, 5, 6]
156
129
  ```
157
130
 
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
131
+ Then, Opts.main.an_array will evaluate to [4, 5, 6] regardless of
132
+ Rails environment and other Opts.main settings will be evaluated
160
133
  according to their per-Rails-environment definitions if present, or
161
- according to their global definitions in config/options/main.rb
134
+ according to their global definitions in config/opts/main.rb
162
135
  otherwise.
163
136
 
137
+ ## Tips ##
138
+
139
+ 1. Many more obvious constant names like Options, or Config, are names
140
+ of Ruby or Rails classes, and will cause name clashes in certain
141
+ contexts. Hence the examples use less neat but reliable Opts name.
142
+
143
+ 2. You can make the options available much earlier in the Rails
144
+ loading process by explicitly requiring them in config/application.rb:
145
+
146
+ ```ruby
147
+ module SomeApplication
148
+ class Application < Rails::Application
149
+ require "config/opts/opts"
150
+
151
+ # ..., rest of the config
152
+ end
153
+ end
154
+ ```
155
+
164
156
  ## Robustness ##
165
157
 
166
158
  dynamic_configuration overwrites method_missing in the context of the
@@ -174,4 +166,4 @@ accidentally modify them. If you try to access a settings group that
174
166
  wasn't defined, you will get an
175
167
  DynamicConfiguration::MissingGroupException, if you try to access a
176
168
  setting that isn't defined of a group that _is_ defined, you will get
177
- a DynamicConfiguration::MissingSettingException.
169
+ a DynamicConfiguration::MissingGroupException.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.14
1
+ 0.3.15
@@ -2,11 +2,11 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: dynamic_configuration 0.3.14 ruby lib
5
+ # stub: dynamic_configuration 0.3.15 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "dynamic_configuration"
9
- s.version = "0.3.14"
9
+ s.version = "0.3.15"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
data/lib/railtie.rb CHANGED
@@ -1,7 +1,9 @@
1
1
  class DynamicConfigurationRailtie < Rails::Railtie
2
2
  config.to_prepare do
3
- DynamicConfiguration.const_names.each do |const_name|
4
- Object.send(:remove_const, const_name) if Object.const_defined?(const_name)
3
+ if Rails.env == 'development'
4
+ DynamicConfiguration.const_names.each do |const_name|
5
+ Object.send(:remove_const, const_name) if Object.const_defined?(const_name)
6
+ end
5
7
  end
6
8
  end
7
9
 
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.3.14
4
+ version: 0.3.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jarosław Rzeszótko