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 +4 -4
- data/README +74 -78
- data/README.markdown +78 -86
- data/VERSION +1 -1
- data/dynamic_configuration.gemspec +2 -2
- data/lib/railtie.rb +4 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a193f927145ad061e46c013dbcf8d9f038733764
|
4
|
+
data.tar.gz: d3d1bfd51da8f1755ef4c2b070446ed0f27c2f69
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 914b381b462dce73c78a7e6725d4aed48ffe52ca7b41b08857fce77e189fc85c2d162fc79856a74c745b6bbb8a7f55923e52114170715be13af625a2ceaeef67
|
7
|
+
data.tar.gz: f3bbb87ec54521bb03df00f16589f02fc638f3e020b6efe843de86d9485d290c6038f2395e526c4a6dd404608b4d6a0d57642a49a67b4845658b760265439f17
|
data/README
CHANGED
@@ -1,25 +1,24 @@
|
|
1
1
|
# dynamic_configuration
|
2
2
|
|
3
|
-
|
4
|
-
|
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
|
6
|
+
* very easy setup with only one line of code
|
10
7
|
|
11
|
-
*
|
8
|
+
* setting files are neat-looking Ruby files, with all of Ruby
|
9
|
+
available for specifying the setting values
|
12
10
|
|
13
|
-
*
|
14
|
-
|
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
|
-
*
|
17
|
-
|
18
|
-
|
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
|
21
|
-
|
22
|
-
|
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
|
-
|
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
|
-
|
34
|
+
DynamicConfiguration::create(:Opts, __FILE__)
|
33
35
|
|
34
|
-
|
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
|
-
|
66
|
-
|
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/
|
69
|
-
|
48
|
+
# config/opts/main.rb
|
49
|
+
owner_email "john@doe.com"
|
70
50
|
|
71
|
-
This will make
|
72
|
-
|
51
|
+
This will make Opts.main.a_string evaluate to "sample value" anywhere
|
52
|
+
in your application:
|
73
53
|
|
74
|
-
|
75
|
-
=> "
|
54
|
+
Opts.main.owner_email
|
55
|
+
=> "john@doe.com"
|
76
56
|
|
77
|
-
The name of the group of
|
78
|
-
|
79
|
-
accessible as
|
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/
|
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
|
-
|
76
|
+
Opts.main.a_string
|
97
77
|
=> "Some string"
|
98
|
-
|
78
|
+
Opts.main.an_array
|
99
79
|
=> [1, 2, 3]
|
100
|
-
|
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
|
111
|
-
environment, for example config/
|
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/
|
114
|
-
|
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/
|
96
|
+
# config/opts/test/main.rb
|
117
97
|
a_string "Test"
|
118
98
|
|
119
|
-
Then
|
120
|
-
environment, while all the other
|
121
|
-
|
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
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
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,
|
139
|
-
Rails environment and other
|
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/
|
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
|
-
|
4
|
-
|
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
|
6
|
+
* very easy setup with only one line of code
|
10
7
|
|
11
|
-
*
|
8
|
+
* setting files are neat-looking Ruby files, with all of Ruby
|
9
|
+
available for specifying the setting values
|
12
10
|
|
13
|
-
*
|
14
|
-
|
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
|
-
*
|
17
|
-
|
18
|
-
|
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
|
21
|
-
|
22
|
-
|
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
|
-
|
31
|
-
|
32
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
74
|
-
|
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/
|
78
|
-
|
51
|
+
# config/opts/main.rb
|
52
|
+
owner_email "john@doe.com"
|
79
53
|
```
|
80
54
|
|
81
|
-
This will make
|
82
|
-
|
55
|
+
This will make Opts.main.a_string evaluate to "sample value" anywhere
|
56
|
+
in your application:
|
83
57
|
|
84
58
|
```ruby
|
85
|
-
|
86
|
-
=> "
|
59
|
+
Opts.main.owner_email
|
60
|
+
=> "john@doe.com"
|
87
61
|
```
|
88
62
|
|
89
|
-
The name of the group of
|
90
|
-
|
91
|
-
accessible as
|
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/
|
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
|
-
|
85
|
+
Opts.main.a_string
|
112
86
|
=> "Some string"
|
113
|
-
|
87
|
+
Opts.main.an_array
|
114
88
|
=> [1, 2, 3]
|
115
|
-
|
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
|
127
|
-
environment, for example config/
|
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/
|
130
|
-
|
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/
|
107
|
+
# config/opts/test/main.rb
|
134
108
|
a_string "Test"
|
135
109
|
```
|
136
110
|
|
137
|
-
Then
|
138
|
-
environment, while all the other
|
139
|
-
|
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
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
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/
|
127
|
+
# config/opts/local/main.rb
|
155
128
|
an_array [4, 5, 6]
|
156
129
|
```
|
157
130
|
|
158
|
-
Then,
|
159
|
-
Rails environment and other
|
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/
|
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::
|
169
|
+
a DynamicConfiguration::MissingGroupException.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
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.
|
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.
|
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
|
-
|
4
|
-
|
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
|
|