ecology 0.0.11 → 0.0.12
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +3 -1
- data/README.md +19 -0
- data/TODO +4 -2
- data/ecology.gemspec +1 -0
- data/lib/ecology/version.rb +1 -1
- data/lib/ecology/version.rb~ +1 -1
- data/lib/ecology.rb +21 -5
- data/test/ecology_test.rb +2 -0
- data/test/erubis_test.rb +46 -0
- data/test/test_helper.rb +9 -1
- data/test/trigger_test.rb +1 -1
- metadata +23 -10
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -176,6 +176,25 @@ on_initialize hook, then the hook will run immediately.
|
|
176
176
|
There is also an on_reset hook. Read "Testing with an Ecology" to
|
177
177
|
find out why you'd ever care about that.
|
178
178
|
|
179
|
+
Ecology.read Etiquette
|
180
|
+
======================
|
181
|
+
|
182
|
+
If you're writing an application, try to call Ecology.read early.
|
183
|
+
Libraries depending on it can then initialize themselves, now that
|
184
|
+
they know where your Ecology data is.
|
185
|
+
|
186
|
+
If you're writing a library, call Ecology.on_initialize early to make
|
187
|
+
sure you get initialized as soon as possible. You'll probably need
|
188
|
+
your own Ecology.read call since your containing application may not
|
189
|
+
use Ecology, or have an Ecology file. Try to make Ecology.read happen
|
190
|
+
as late as you can - the first time you genuinely need the data, for
|
191
|
+
instance.
|
192
|
+
|
193
|
+
For test purposes, if you set a bunch of data with
|
194
|
+
Ecology.on_initialize, try to register Ecology.on_reset to clear that
|
195
|
+
same data. Then a test using Ecology.reset can test your library with
|
196
|
+
different settings.
|
197
|
+
|
179
198
|
Testing with an Ecology
|
180
199
|
=======================
|
181
200
|
|
data/TODO
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
-
* Use Erubis before evaluating
|
2
|
-
|
3
1
|
* On Ecology.read calls, make sure ecology filename hasn't changed (and warn if it has)
|
4
2
|
|
5
3
|
* Have Ecology.read try to do a read relative to the executable's directory first rather than relative to cwd.
|
4
|
+
|
5
|
+
* Register properties by top-level tag
|
6
|
+
|
7
|
+
* Allow setting environment variables based on Ecology
|
data/ecology.gemspec
CHANGED
data/lib/ecology/version.rb
CHANGED
data/lib/ecology/version.rb~
CHANGED
data/lib/ecology.rb
CHANGED
@@ -39,10 +39,15 @@ module Ecology
|
|
39
39
|
mutex.synchronize do
|
40
40
|
return if @ecology_initialized
|
41
41
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
42
|
+
filelist = [ENV["ECOLOGY_SPEC"], ecology_pathname, default_ecology_name]
|
43
|
+
filelist.detect do |file_path|
|
44
|
+
if file_path && (File.exist?(file_path) || File.exist?(file_path + ".erb"))
|
45
|
+
@data = {}
|
46
|
+
contents = merge_with_overrides(file_path)
|
47
|
+
true
|
48
|
+
else
|
49
|
+
false
|
50
|
+
end
|
46
51
|
end
|
47
52
|
|
48
53
|
@application ||= File.basename($0)
|
@@ -103,7 +108,18 @@ module Ecology
|
|
103
108
|
end
|
104
109
|
|
105
110
|
def merge_with_overrides(file_path)
|
106
|
-
|
111
|
+
if File.exist?(file_path + ".erb")
|
112
|
+
contents = File.read(file_path + ".erb")
|
113
|
+
|
114
|
+
require "erubis"
|
115
|
+
var_hash = {
|
116
|
+
:ecology_version => Ecology::VERSION,
|
117
|
+
:filename => "#{file_path}.erb",
|
118
|
+
}
|
119
|
+
contents = Erubis::Eruby.new(contents).result(var_hash)
|
120
|
+
else
|
121
|
+
contents = File.read(file_path)
|
122
|
+
end
|
107
123
|
file_data = MultiJson.decode(contents);
|
108
124
|
|
109
125
|
return unless file_data
|
data/test/ecology_test.rb
CHANGED
@@ -16,6 +16,7 @@ class EcologyTest < Scope::TestCase
|
|
16
16
|
|
17
17
|
should "respect the ECOLOGY_SPEC environment variable" do
|
18
18
|
ENV['ECOLOGY_SPEC'] = '/tmp/bobo.txt'
|
19
|
+
File.expects(:exist?).with('/tmp/bobo.txt.erb').returns(false).at_least_once
|
19
20
|
File.expects(:exist?).with('/tmp/bobo.txt').returns(true)
|
20
21
|
File.expects(:read).with('/tmp/bobo.txt').returns('{ "application": "foo_app" }')
|
21
22
|
Ecology.read
|
@@ -31,6 +32,7 @@ class EcologyTest < Scope::TestCase
|
|
31
32
|
$0 = "whatever_app.rb"
|
32
33
|
|
33
34
|
ENV['ECOLOGY_SPEC'] = nil
|
35
|
+
File.expects(:exist?).with("whatever_app.ecology.erb").returns(false).at_least_once
|
34
36
|
File.expects(:exist?).with("whatever_app.ecology").returns(false)
|
35
37
|
|
36
38
|
Ecology.read
|
data/test/erubis_test.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "test_helper.rb")
|
2
|
+
require "multi_json"
|
3
|
+
|
4
|
+
class ErubisTest < Scope::TestCase
|
5
|
+
setup do
|
6
|
+
Ecology.reset
|
7
|
+
end
|
8
|
+
|
9
|
+
context "with a .erb ecology" do
|
10
|
+
setup do
|
11
|
+
set_up_ecology(<<ECOLOGY_CONTENTS, "some_app.ecology.erb")
|
12
|
+
{
|
13
|
+
"application": "SomeApp",
|
14
|
+
"domain": {
|
15
|
+
"property1" :
|
16
|
+
<% if ENV["BOBO"] %>
|
17
|
+
37
|
18
|
+
<% else %>
|
19
|
+
42
|
20
|
+
<% end %>
|
21
|
+
},
|
22
|
+
"bobo": <%= MultiJson.encode(ENV["BOBO"]) %>
|
23
|
+
}
|
24
|
+
ECOLOGY_CONTENTS
|
25
|
+
|
26
|
+
ENV["BOBO"] = nil
|
27
|
+
end
|
28
|
+
|
29
|
+
should "Parse conditionally with Erubis" do
|
30
|
+
ENV["BOBO"] = "true"
|
31
|
+
Ecology.read
|
32
|
+
assert_equal 37, Ecology.property("domain::property1")
|
33
|
+
end
|
34
|
+
|
35
|
+
should "Parse conditionally with Erubis when a variable is unset" do
|
36
|
+
Ecology.read
|
37
|
+
assert_equal 42, Ecology.property("domain::property1")
|
38
|
+
end
|
39
|
+
|
40
|
+
# should "Return values from Erubis" do
|
41
|
+
# ENV["BOBO"] = { "a" => "b", "c" => "d" }
|
42
|
+
# Ecology.read
|
43
|
+
# assert_equal { "a" => "b", "c" => "d" }, Ecology.property("bobo")
|
44
|
+
# end
|
45
|
+
end
|
46
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -10,7 +10,15 @@ require "ecology"
|
|
10
10
|
|
11
11
|
class Scope::TestCase
|
12
12
|
def set_up_ecology(file_contents, filename = "some.ecology")
|
13
|
-
|
13
|
+
match = filename.match(/^(.*)\.erb$/)
|
14
|
+
if match
|
15
|
+
ENV["ECOLOGY_SPEC"] = match[1]
|
16
|
+
File.stubs(:exist?).with(match[1]).returns(false)
|
17
|
+
else
|
18
|
+
ENV["ECOLOGY_SPEC"] = filename
|
19
|
+
end
|
20
|
+
|
21
|
+
File.stubs(:exist?).with(filename + ".erb").returns(false)
|
14
22
|
File.stubs(:exist?).with(filename).returns(true)
|
15
23
|
File.expects(:read).with(filename).returns(file_contents).at_least_once
|
16
24
|
end
|
data/test/trigger_test.rb
CHANGED
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: ecology
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.12
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Noah Gibbs
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-10-
|
13
|
+
date: 2011-10-19 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: multi_json
|
@@ -24,49 +24,60 @@ dependencies:
|
|
24
24
|
type: :runtime
|
25
25
|
version_requirements: *id001
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
|
-
name:
|
27
|
+
name: erubis
|
28
28
|
prerelease: false
|
29
29
|
requirement: &id002 !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: "0"
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id002
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: bundler
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
30
41
|
none: false
|
31
42
|
requirements:
|
32
43
|
- - ~>
|
33
44
|
- !ruby/object:Gem::Version
|
34
45
|
version: 1.0.10
|
35
46
|
type: :development
|
36
|
-
version_requirements: *
|
47
|
+
version_requirements: *id003
|
37
48
|
- !ruby/object:Gem::Dependency
|
38
49
|
name: scope
|
39
50
|
prerelease: false
|
40
|
-
requirement: &
|
51
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
41
52
|
none: false
|
42
53
|
requirements:
|
43
54
|
- - ~>
|
44
55
|
- !ruby/object:Gem::Version
|
45
56
|
version: 0.2.1
|
46
57
|
type: :development
|
47
|
-
version_requirements: *
|
58
|
+
version_requirements: *id004
|
48
59
|
- !ruby/object:Gem::Dependency
|
49
60
|
name: mocha
|
50
61
|
prerelease: false
|
51
|
-
requirement: &
|
62
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
52
63
|
none: false
|
53
64
|
requirements:
|
54
65
|
- - ">="
|
55
66
|
- !ruby/object:Gem::Version
|
56
67
|
version: "0"
|
57
68
|
type: :development
|
58
|
-
version_requirements: *
|
69
|
+
version_requirements: *id005
|
59
70
|
- !ruby/object:Gem::Dependency
|
60
71
|
name: rake
|
61
72
|
prerelease: false
|
62
|
-
requirement: &
|
73
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
63
74
|
none: false
|
64
75
|
requirements:
|
65
76
|
- - ">="
|
66
77
|
- !ruby/object:Gem::Version
|
67
78
|
version: "0"
|
68
79
|
type: :development
|
69
|
-
version_requirements: *
|
80
|
+
version_requirements: *id006
|
70
81
|
description: |
|
71
82
|
Ecology sets configuration data for an application based
|
72
83
|
on environment variables and other factors. It is meant
|
@@ -95,6 +106,7 @@ files:
|
|
95
106
|
- test/ecology_test.rb
|
96
107
|
- test/environment_test.rb
|
97
108
|
- test/environment_var_test.rb
|
109
|
+
- test/erubis_test.rb
|
98
110
|
- test/override_properties_test.rb
|
99
111
|
- test/path_test.rb
|
100
112
|
- test/property_test.rb
|
@@ -133,6 +145,7 @@ test_files:
|
|
133
145
|
- test/ecology_test.rb
|
134
146
|
- test/environment_test.rb
|
135
147
|
- test/environment_var_test.rb
|
148
|
+
- test/erubis_test.rb
|
136
149
|
- test/override_properties_test.rb
|
137
150
|
- test/path_test.rb
|
138
151
|
- test/property_test.rb
|