dynamic_configuration 0.2.0 → 0.3.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/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (C) 2012 Jarosław Rzeszótko
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
4
+ this software and associated documentation files (the "Software"), to deal in
5
+ the Software without restriction, including without limitation the rights to
6
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
7
+ of the Software, and to permit persons to whom the Software is furnished to do
8
+ so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.
data/README ADDED
@@ -0,0 +1,157 @@
1
+ # dynamic_configuration
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:
8
+
9
+ * very easy setup with only two lines of code
10
+
11
+ * configuration files are very clean-looking Ruby files
12
+
13
+ * in Rails development environment, one doesn't have to restart the
14
+ server to add/remove/modify a setting
15
+
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
19
+
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)
23
+
24
+ * throughout field- and unit- tested
25
+
26
+ Developed as part of my work for http://www.tutoria.de/.
27
+
28
+ ## Setup
29
+
30
+ ### Rails 3 application:
31
+
32
+ Add the gem to your Gemfile:
33
+
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/")
59
+
60
+ ## Usage
61
+
62
+ ### Basics
63
+
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:
67
+
68
+ # config/options/main.rb
69
+ a_string "sample value"
70
+
71
+ This will make Options.main.a_string evaluate to "sample value"
72
+ anywhere in your application:
73
+
74
+ Options.main.a_string
75
+ => "sample value"
76
+
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.
80
+
81
+ The value of each settings can be any kind of Ruby object, so the
82
+ following is a valid config file:
83
+
84
+ # config/options/main.rb
85
+ a_string "Some string"
86
+
87
+ an_array [1, 2, 3]
88
+
89
+ a_fancy_string_array(%w{
90
+ string1
91
+ string2
92
+ })
93
+
94
+ Which you can use in other places of your application like this:
95
+
96
+ Options.main.a_string
97
+ => "Some string"
98
+ Options.main.an_array
99
+ => [1, 2, 3]
100
+ Options.main.a_fancy_string_array
101
+ => ["string1", "string2"]
102
+
103
+ Note that hash map values have to be wrapped in parenthesis, since
104
+ defining a setting works under the hood as a Ruby method call, so it
105
+ has to have the syntax of one.
106
+
107
+ ### Overriding settings per Rails environment ###
108
+
109
+ 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
112
+ 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:
115
+
116
+ # config/options/test/main.rb
117
+ a_string "Test"
118
+
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.
122
+
123
+ ### Overriding settings locally ###
124
+
125
+ This is mostly meant for applications that are stored in a version
126
+ 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
136
+ an_array [4, 5, 6]
137
+
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
140
+ according to their per-Rails-environment definitions if present, or
141
+ according to their global definitions in config/options/main.rb
142
+ otherwise.
143
+
144
+ ## Robustness ##
145
+
146
+ dynamic_configuration overwrites method_missing in the context of the
147
+ configuration files to enable the syntax it provides. It doesn't do
148
+ anything to method_missing globally, nor does it do any other "magic"
149
+ that could affect any piece of your application other then the
150
+ configuration files themselves.
151
+
152
+ All the settings are frozen as soon as they are defined, so you won't
153
+ accidentally modify them. If you try to access a settings group that
154
+ wasn't defined, you will get an
155
+ DynamicConfiguration::MissingGroupException, if you try to access a
156
+ setting that isn't defined of a group that _is_ defined, you will get
157
+ a DynamicConfiguration::MissingGroupException.
data/README.markdown CHANGED
@@ -174,4 +174,4 @@ accidentally modify them. If you try to access a settings group that
174
174
  wasn't defined, you will get an
175
175
  DynamicConfiguration::MissingGroupException, if you try to access a
176
176
  setting that isn't defined of a group that _is_ defined, you will get
177
- a DynamicConfiguration::MissingGroupException.
177
+ a DynamicConfiguration::MissingSettingException.
data/Rakefile CHANGED
@@ -19,7 +19,7 @@ Jeweler::Tasks.new do |gem|
19
19
  gem.email = "jrzeszotko@gmail.com"
20
20
  gem.homepage = "http://github.com/jaroslawr/dynamic_configuration"
21
21
  gem.authors = ["Jarosław Rzeszótko"]
22
- gem.add_dependency('builder')
22
+ gem.add_dependency('blankslate')
23
23
  end
24
24
 
25
25
  Jeweler::RubygemsDotOrgTasks.new
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.3.0
@@ -5,17 +5,21 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{dynamic_configuration}
8
- s.version = "0.2.0"
8
+ s.version = "0.3.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}]
12
- s.date = %q{2012-01-26}
12
+ s.date = %q{2013-01-21}
13
13
  s.description = %q{Flexible configuration library for Ruby and Rails applications.}
14
14
  s.email = %q{jrzeszotko@gmail.com}
15
15
  s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README",
16
18
  "README.markdown"
17
19
  ]
18
20
  s.files = [
21
+ "LICENSE",
22
+ "README",
19
23
  "README.markdown",
20
24
  "Rakefile",
21
25
  "VERSION",
@@ -37,12 +41,12 @@ Gem::Specification.new do |s|
37
41
  s.specification_version = 3
38
42
 
39
43
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
40
- s.add_runtime_dependency(%q<builder>, [">= 0"])
44
+ s.add_runtime_dependency(%q<blankslate>, [">= 0"])
41
45
  else
42
- s.add_dependency(%q<builder>, [">= 0"])
46
+ s.add_dependency(%q<blankslate>, [">= 0"])
43
47
  end
44
48
  else
45
- s.add_dependency(%q<builder>, [">= 0"])
49
+ s.add_dependency(%q<blankslate>, [">= 0"])
46
50
  end
47
51
  end
48
52
 
@@ -79,7 +79,9 @@ module DynamicConfiguration
79
79
  end
80
80
  end
81
81
 
82
- class Config < ::BlankSlate
82
+ class Config < ::BlankSlate
83
+ reveal :freeze
84
+
83
85
  def initialize(const_name, config_path)
84
86
  @const_name, @config_path = const_name, config_path
85
87
  end
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.2.0
4
+ version: 0.3.0
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: 2012-01-26 00:00:00.000000000 Z
12
+ date: 2013-01-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: builder
16
- requirement: &76717450 !ruby/object:Gem::Requirement
15
+ name: blankslate
16
+ requirement: &77485380 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,14 +21,18 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *76717450
24
+ version_requirements: *77485380
25
25
  description: Flexible configuration library for Ruby and Rails applications.
26
26
  email: jrzeszotko@gmail.com
27
27
  executables: []
28
28
  extensions: []
29
29
  extra_rdoc_files:
30
+ - LICENSE
31
+ - README
30
32
  - README.markdown
31
33
  files:
34
+ - LICENSE
35
+ - README
32
36
  - README.markdown
33
37
  - Rakefile
34
38
  - VERSION