rack-config-flexible 0.1.1 → 0.1.2
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.md +36 -5
- data/lib/rack/config/flexible.rb +19 -0
- metadata +3 -3
data/README.md
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
rack-config-flexible
|
2
2
|
====================
|
3
3
|
|
4
|
-
|
4
|
+
A flexible configuration middleware for Rack that provides a simple DSL,
|
5
|
+
as well as the ability to easily load configuration from yaml files.
|
5
6
|
|
6
7
|
Licensing
|
7
8
|
=========
|
@@ -76,8 +77,8 @@ Any calls to _set_ after _environment_ or _section_ will override
|
|
76
77
|
data loaded from the yaml file if the same key is specified.
|
77
78
|
Otherwise, they'll just add the values to the hash per usual.
|
78
79
|
|
79
|
-
Loading the Entire Configuration from
|
80
|
-
|
80
|
+
Loading the Entire Configuration from Yaml
|
81
|
+
==========================================
|
81
82
|
|
82
83
|
You can load the entire configuration from a single file, or a
|
83
84
|
directory tree.
|
@@ -93,7 +94,27 @@ use Rack::Config::Flexible :from_file => 'settings.yaml' do
|
|
93
94
|
end
|
94
95
|
```
|
95
96
|
|
96
|
-
|
97
|
+
The _settings.yaml_ file should be laid out like:
|
98
|
+
|
99
|
+
```yaml
|
100
|
+
environment:
|
101
|
+
section:
|
102
|
+
key: value
|
103
|
+
```
|
104
|
+
|
105
|
+
So, the equivalent of the initial example would be:
|
106
|
+
|
107
|
+
```yaml
|
108
|
+
production:
|
109
|
+
data:
|
110
|
+
key: value
|
111
|
+
|
112
|
+
development:
|
113
|
+
data:
|
114
|
+
key: dev_value
|
115
|
+
```
|
116
|
+
|
117
|
+
This example loads from a directory tree:
|
97
118
|
|
98
119
|
```ruby
|
99
120
|
require 'rack/config/flexible'
|
@@ -110,8 +131,18 @@ The directory tree is expected to be laid out like:
|
|
110
131
|
|
111
132
|
Where each directory under _settings_ is an _environment_,
|
112
133
|
containg a separate yaml file for each _section_.
|
113
|
-
The
|
134
|
+
The yaml file itself will only hold key-value pairs for
|
114
135
|
that particular _section_.
|
115
136
|
|
116
137
|
See the inline documentation for more details.
|
117
138
|
|
139
|
+
Caveats
|
140
|
+
=======
|
141
|
+
|
142
|
+
Do *not* use this module and _Rack::Config_ at the same time! This module
|
143
|
+
will remove the constant for _Rack::Config_ to avoid a conflict with _Rack::Config_
|
144
|
+
being a class, whereas here we use it as a module.
|
145
|
+
|
146
|
+
This means no new instances of _Rack::Config_ can be so easily created after this module is loaded.
|
147
|
+
However, existing instances should still work.
|
148
|
+
|
data/lib/rack/config/flexible.rb
CHANGED
@@ -1,6 +1,25 @@
|
|
1
|
+
#
|
2
|
+
# Rack::Config::Flexible - Configuration middleware for Rack
|
3
|
+
#
|
4
|
+
# Copyright (C) 2012 Tim Hentenaar. All Rights Reserved.
|
5
|
+
#
|
6
|
+
# Licensed under the Simplified BSD License.
|
7
|
+
# See the LICENSE file for details.
|
8
|
+
#
|
1
9
|
require 'yaml'
|
2
10
|
|
3
11
|
module Rack
|
12
|
+
|
13
|
+
#
|
14
|
+
# Remove the constant for Rack::Config otherwise we get
|
15
|
+
# a TypeError since Rack::Config is a class, not a module.
|
16
|
+
#
|
17
|
+
# It seems the original instances will still be preserved
|
18
|
+
#
|
19
|
+
if Rack::Config.is_a?(Class)
|
20
|
+
Rack.send(:remove_const,'Config')
|
21
|
+
end
|
22
|
+
|
4
23
|
module Config
|
5
24
|
#
|
6
25
|
# === Overview
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-config-flexible
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-11-
|
12
|
+
date: 2012-11-19 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: ! " Rack::Config::Flexible is an alternative to Rack::Config,\n offering
|
15
15
|
much greater flexibility.\n \n Configuration options are stored as key-value pairs
|
@@ -47,7 +47,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
47
47
|
version: '0'
|
48
48
|
requirements: []
|
49
49
|
rubyforge_project:
|
50
|
-
rubygems_version: 1.8.
|
50
|
+
rubygems_version: 1.8.23
|
51
51
|
signing_key:
|
52
52
|
specification_version: 3
|
53
53
|
summary: An alternative to Rack::Config, offering much greater flexibility
|