constellation 0.1.0 → 0.1.1
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 +43 -1
- data/lib/constellation.rb +6 -0
- metadata +9 -9
data/README.md
CHANGED
@@ -4,7 +4,7 @@ Constellation is a powerful configuration system. It's great for
|
|
4
4
|
API client libraries and applications and anywhere else you need to
|
5
5
|
let your users set some configuration parameters.
|
6
6
|
|
7
|
-
##
|
7
|
+
## Putting Settings In
|
8
8
|
|
9
9
|
### Ruby Parameters
|
10
10
|
|
@@ -112,3 +112,45 @@ class MyConfiguration
|
|
112
112
|
end
|
113
113
|
end
|
114
114
|
```
|
115
|
+
|
116
|
+
## Getting Settings Out
|
117
|
+
|
118
|
+
Given a `Constellation` configuration object
|
119
|
+
|
120
|
+
```ruby
|
121
|
+
c = MyConfiguration.new(:foo => 'bar')
|
122
|
+
```
|
123
|
+
|
124
|
+
you can get the settings out in a few ways.
|
125
|
+
|
126
|
+
Keys are available as methods:
|
127
|
+
|
128
|
+
```ruby
|
129
|
+
c.foo # => "bar"
|
130
|
+
```
|
131
|
+
|
132
|
+
Keys are converted to `String`s and available via `[]`:
|
133
|
+
|
134
|
+
```ruby
|
135
|
+
c['foo'] # => "bar"
|
136
|
+
```
|
137
|
+
|
138
|
+
`to_hash` will return all of the settings:
|
139
|
+
|
140
|
+
```ruby
|
141
|
+
c.to_hash # => { "foo" => "bar" }
|
142
|
+
```
|
143
|
+
|
144
|
+
The enumerable methods are available:
|
145
|
+
|
146
|
+
```ruby
|
147
|
+
c.map { |k,v| k + ':' + v } # => [ "foo:bar" ]
|
148
|
+
```
|
149
|
+
|
150
|
+
If you have loaded [`activesupport`](http://rubygems.org/gems/activesupport),
|
151
|
+
the configuration will be available with
|
152
|
+
[indifferent access](http://guides.rubyonrails.org/active_support_core_extensions.html#indifferent-access):
|
153
|
+
|
154
|
+
```ruby
|
155
|
+
c[:foo] # => "bar"
|
156
|
+
```
|
data/lib/constellation.rb
CHANGED
@@ -22,6 +22,7 @@ module Constellation
|
|
22
22
|
|
23
23
|
def initialize(data = nil)
|
24
24
|
@data = {}
|
25
|
+
indifferentize!
|
25
26
|
reverse_merge(data || {})
|
26
27
|
fall_back_on_env
|
27
28
|
fall_back_on_file(Dir.pwd)
|
@@ -57,6 +58,11 @@ module Constellation
|
|
57
58
|
|
58
59
|
attr_reader :data
|
59
60
|
|
61
|
+
def indifferentize!
|
62
|
+
return unless data.respond_to?(:with_indifferent_access)
|
63
|
+
@data = data.with_indifferent_access
|
64
|
+
end
|
65
|
+
|
60
66
|
def fall_back_on_env
|
61
67
|
env_values = self.class.env_params.inject({}) do |sum, (prop, env_prop)|
|
62
68
|
sum[prop] = ENV[env_prop] if ENV.has_key?(env_prop)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: constellation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2012-03-10 00:00:00.000000000Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: multi_json
|
16
|
-
requirement: &
|
16
|
+
requirement: &70178361315940 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70178361315940
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rspec
|
27
|
-
requirement: &
|
27
|
+
requirement: &70178361315460 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70178361315460
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: fakefs
|
38
|
-
requirement: &
|
38
|
+
requirement: &70178361314880 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70178361314880
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: mocha
|
49
|
-
requirement: &
|
49
|
+
requirement: &70178361314260 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,7 +54,7 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70178361314260
|
58
58
|
description: Load configuration settings from ENV, dotfiles, and gems
|
59
59
|
email:
|
60
60
|
- james.a.rosen@gmail.com
|