constellation 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -8,11 +8,11 @@ let your users set some configuration parameters.
8
8
 
9
9
  ### Ruby Parameters
10
10
 
11
- Start by creating a class and calling `acts_as_constellation`
11
+ Start by creating a class and calling `Constellation.enhance`:
12
12
 
13
13
  ```ruby
14
14
  class MyConfiguration
15
- acts_as_constellation
15
+ Constellation.enhance self
16
16
  end
17
17
  ```
18
18
 
@@ -39,6 +39,7 @@ ENV['MY_FOO'] = 'bar'
39
39
  ...
40
40
  config = MyConfiguration.new
41
41
  config.foo # => "bar"
42
+ ```
42
43
 
43
44
  ### Configuration Files
44
45
 
@@ -110,4 +111,4 @@ class MyConfiguration
110
111
  result
111
112
  end
112
113
  end
113
- ```
114
+ ```
data/lib/constellation.rb CHANGED
@@ -6,12 +6,10 @@ module Constellation
6
6
  end
7
7
  end
8
8
 
9
- module ActsAs
10
- def acts_as_constellation
11
- extend Constellation::ClassMethods
12
- self.env_params = {}
13
- include Constellation::InstanceMethods
14
- end
9
+ def self.enhance(klass)
10
+ klass.extend Constellation::ClassMethods
11
+ klass.env_params = {}
12
+ klass.send :include, Constellation::InstanceMethods
15
13
  end
16
14
 
17
15
  module ClassMethods
@@ -20,6 +18,8 @@ module Constellation
20
18
 
21
19
  module InstanceMethods
22
20
 
21
+ include Enumerable
22
+
23
23
  def initialize(data = nil)
24
24
  @data = {}
25
25
  reverse_merge(data || {})
@@ -29,10 +29,18 @@ module Constellation
29
29
  fall_back_on_gems
30
30
  end
31
31
 
32
+ def to_hash
33
+ @data.dup
34
+ end
35
+
32
36
  def [](key)
33
37
  @data[key.to_s]
34
38
  end
35
39
 
40
+ def each(&block)
41
+ @data.each &block
42
+ end
43
+
36
44
  def method_missing(name, *arguments, &block)
37
45
  if data.has_key?(name.to_s)
38
46
  data[name.to_s]
@@ -110,5 +118,3 @@ module Constellation
110
118
  end
111
119
 
112
120
  end
113
-
114
- Class.send :include, Constellation::ActsAs
@@ -10,7 +10,7 @@ describe Constellation do
10
10
 
11
11
  let(:config_class) do
12
12
  Class.new.tap do |c|
13
- c.acts_as_constellation
13
+ Constellation.enhance c
14
14
  c.env_params = { foo: 'MY_FOO', bar: 'MY_BAR' }
15
15
  c.config_file = path
16
16
  c.load_from_gems = load_from_gems
@@ -121,4 +121,29 @@ describe Constellation do
121
121
  it('parses with the given parse method') { subject.foo.should == 'colonfoo' }
122
122
  end
123
123
  end
124
+
125
+ describe '#to_hash' do
126
+ subject { config_class.new(foo: 'FOO') }
127
+
128
+ it 'returns a Hash containing the settings' do
129
+ subject.to_hash['foo'].should == 'FOO'
130
+ end
131
+
132
+ it 'returns a defensive copy' do
133
+ subject.to_hash['foo'] = 'BAR'
134
+ subject.foo.should == 'FOO'
135
+ end
136
+ end
137
+
138
+ describe 'enumerable methods' do
139
+ subject { config_class.new(foo: 'FOO') }
140
+
141
+ it 'enumerates over the settings' do
142
+ result = []
143
+ subject.each { |k,v| result << [k,v] }
144
+ result.should == [ ['foo', 'FOO'] ]
145
+ end
146
+
147
+ it('is an Enumerable') { subject.should be_kind_of(Enumerable) }
148
+ end
124
149
  end
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.0.2
4
+ version: 0.1.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-03-08 00:00:00.000000000Z
12
+ date: 2012-03-10 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: multi_json
16
- requirement: &70109801362700 !ruby/object:Gem::Requirement
16
+ requirement: &70157990197000 !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: *70109801362700
24
+ version_requirements: *70157990197000
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &70109801362020 !ruby/object:Gem::Requirement
27
+ requirement: &70157990196420 !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: *70109801362020
35
+ version_requirements: *70157990196420
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: fakefs
38
- requirement: &70109801360920 !ruby/object:Gem::Requirement
38
+ requirement: &70157990195860 !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: *70109801360920
46
+ version_requirements: *70157990195860
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: mocha
49
- requirement: &70109801360340 !ruby/object:Gem::Requirement
49
+ requirement: &70157990195320 !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: *70109801360340
57
+ version_requirements: *70157990195320
58
58
  description: Load configuration settings from ENV, dotfiles, and gems
59
59
  email:
60
60
  - james.a.rosen@gmail.com