couchrest_model_config 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/.rvmrc +1 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +83 -0
- data/PUBLIC_DOMAIN +103 -0
- data/VERSION +1 -0
- data/couchrest_model_config.gemspec +24 -0
- data/features/configure_database.feature +80 -0
- data/features/configure_environment.feature +12 -0
- data/features/configure_namespace_model.feature +9 -0
- data/features/configure_server.feature +23 -0
- data/features/reset.feature +6 -0
- data/features/step_definitions/configure_steps.rb +223 -0
- data/features/step_definitions/environment_steps.rb +24 -0
- data/features/step_definitions/reset_steps.rb +35 -0
- data/features/support/env.rb +4 -0
- data/features/support/hooks.rb +3 -0
- data/lib/couchrest_model_config.rb +5 -0
- data/lib/couchrest_model_config/config.rb +74 -0
- data/lib/couchrest_model_config/couchrest_model_base.rb +13 -0
- data/lib/couchrest_model_config/model.rb +61 -0
- data/lib/couchrest_model_config/server.rb +42 -0
- data/readme.markdown +153 -0
- metadata +145 -0
data/.gitignore
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm gemset use couchrest_model_database_config
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
couchrest_model_database_config (0.0.0)
|
5
|
+
couchrest_model (~> 1.0.0)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: http://rubygems.org/
|
9
|
+
specs:
|
10
|
+
abstract (1.0.0)
|
11
|
+
actionpack (3.0.7)
|
12
|
+
activemodel (= 3.0.7)
|
13
|
+
activesupport (= 3.0.7)
|
14
|
+
builder (~> 2.1.2)
|
15
|
+
erubis (~> 2.6.6)
|
16
|
+
i18n (~> 0.5.0)
|
17
|
+
rack (~> 1.2.1)
|
18
|
+
rack-mount (~> 0.6.14)
|
19
|
+
rack-test (~> 0.5.7)
|
20
|
+
tzinfo (~> 0.3.23)
|
21
|
+
activemodel (3.0.7)
|
22
|
+
activesupport (= 3.0.7)
|
23
|
+
builder (~> 2.1.2)
|
24
|
+
i18n (~> 0.5.0)
|
25
|
+
activesupport (3.0.7)
|
26
|
+
builder (2.1.2)
|
27
|
+
couchrest (1.0.2)
|
28
|
+
json (~> 1.5.1)
|
29
|
+
mime-types (~> 1.15)
|
30
|
+
rest-client (~> 1.6.1)
|
31
|
+
couchrest_model (1.0.0)
|
32
|
+
activemodel (~> 3.0.0)
|
33
|
+
couchrest (~> 1.0.1)
|
34
|
+
mime-types (~> 1.15)
|
35
|
+
railties (~> 3.0.0)
|
36
|
+
rspec (>= 2.0.0)
|
37
|
+
tzinfo (~> 0.3.22)
|
38
|
+
cucumber (0.10.2)
|
39
|
+
builder (>= 2.1.2)
|
40
|
+
diff-lcs (>= 1.1.2)
|
41
|
+
gherkin (>= 2.3.5)
|
42
|
+
json (>= 1.4.6)
|
43
|
+
term-ansicolor (>= 1.0.5)
|
44
|
+
diff-lcs (1.1.2)
|
45
|
+
erubis (2.6.6)
|
46
|
+
abstract (>= 1.0.0)
|
47
|
+
gherkin (2.3.6)
|
48
|
+
json (>= 1.4.6)
|
49
|
+
i18n (0.5.0)
|
50
|
+
json (1.5.1)
|
51
|
+
mime-types (1.16)
|
52
|
+
rack (1.2.2)
|
53
|
+
rack-mount (0.6.14)
|
54
|
+
rack (>= 1.0.0)
|
55
|
+
rack-test (0.5.7)
|
56
|
+
rack (>= 1.0)
|
57
|
+
railties (3.0.7)
|
58
|
+
actionpack (= 3.0.7)
|
59
|
+
activesupport (= 3.0.7)
|
60
|
+
rake (>= 0.8.7)
|
61
|
+
thor (~> 0.14.4)
|
62
|
+
rake (0.8.7)
|
63
|
+
rest-client (1.6.1)
|
64
|
+
mime-types (>= 1.16)
|
65
|
+
rspec (2.4.0)
|
66
|
+
rspec-core (~> 2.4.0)
|
67
|
+
rspec-expectations (~> 2.4.0)
|
68
|
+
rspec-mocks (~> 2.4.0)
|
69
|
+
rspec-core (2.4.0)
|
70
|
+
rspec-expectations (2.4.0)
|
71
|
+
diff-lcs (~> 1.1.2)
|
72
|
+
rspec-mocks (2.4.0)
|
73
|
+
term-ansicolor (1.0.5)
|
74
|
+
thor (0.14.6)
|
75
|
+
tzinfo (0.3.27)
|
76
|
+
|
77
|
+
PLATFORMS
|
78
|
+
ruby
|
79
|
+
|
80
|
+
DEPENDENCIES
|
81
|
+
couchrest_model_database_config!
|
82
|
+
cucumber (~> 0.10.0)
|
83
|
+
rspec (~> 2.4.0)
|
data/PUBLIC_DOMAIN
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
This software is PUBLIC DOMAIN
|
2
|
+
|
3
|
+
|
4
|
+
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
|
5
|
+
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
|
6
|
+
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
|
7
|
+
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
|
8
|
+
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
|
9
|
+
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,;;iiii;;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
|
10
|
+
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,;ijffffffffffffffffji;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
|
11
|
+
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,;iffffffffffffffffffffffffffi;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
|
12
|
+
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, iffffffffffffffffffffffffffffffi ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
|
13
|
+
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,ijffffffffffffffffffffffffffffffffffji,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
|
14
|
+
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,iffffffffffffffffffffffffffffffffffffffffi,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
|
15
|
+
,,,,,,,,,,,,,,,,,,,,,,,,,,,jffffffffffffffffffffffffffffffffffffffffffffj,,,,,,,,,,,,,,,,,,,,,,,,,,,
|
16
|
+
,,,,,,,,,,,,,,,,,,,,,,,,,,tfffffffffffffffffffffffffffffffffffffffffffffft,,,,,,,,,,,,,,,,,,,,,,,,,,
|
17
|
+
,,,,,,,,,,,,,,,,,,,,,,,,;ffffffffffffffffffffffffffffffffffffffffffffffffff;,,,,,,,,,,,,,,,,,,,,,,,,
|
18
|
+
,,,,,,,,,,,,,,,,,,,,,,,ffffffffffffffffffffffjt;;,,;;tjffffffffffffffffffffff,,,,,,,,,,,,,,,,,,,,,,,
|
19
|
+
,,,,,,,,,,,,,,,,,,,,,;fffffffffffffffffft: :tffffffffffffffffff;,,,,,,,,,,,,,,,,,,,,,
|
20
|
+
,,,,,,,,,,,,,,,,,,,,,jfffffffffffffffft. .tffffffffffffffffj,,,,,,,,,,,,,,,,,,,,,
|
21
|
+
,,,,,,,,,,,,,,,,,,,ifffffffffffffffi: :ifffffffffffffffi,,,,,,,,,,,,,,,,,,,
|
22
|
+
,,,,,,,,,,,,,,,,,,tffffffffffffffi ifffffffffffffft,,,,,,,,,,,,,,,,,,
|
23
|
+
,,,,,,,,,,,,,,,,,ifffffffffffff, ,fffffffffffffi,,,,,,,,,,,,,,,,,
|
24
|
+
,,,,,,,,,,,,,,,,,fffffffffffffi ifffffffffffff,,,,,,,,,,,,,,,,,
|
25
|
+
,,,,,,,,,,,,,,,;jffffffffffff ffffffffffffj;,,,,,,,,,,,,,,,
|
26
|
+
,,,,,,,,,,,,,,,ffffffffffff: jffffffffffffff,,,,,,,,,,,,,,,
|
27
|
+
,,,,,,,,,,,,,,ffffffffffff. jffffffffffffffff,,,,,,,,,,,,,,
|
28
|
+
,,,,,,,,,,,,,;ffffffffffft :fffffffffffffffff;,,,,,,,,,,,,,
|
29
|
+
,,,,,,,,,,,,,ffffffffffft ,tfffffft; jfffffffffffffffffff,,,,,,,,,,,,,
|
30
|
+
,,,,,,,,,,,,tffffffffff. ;ffffffffffffffff; jfffffffffffffffffffft,,,,,,,,,,,,
|
31
|
+
,,,,,,,,,,,jffffffffff: ,ffffffffffffffffffffff, jffffffffffffffffffffffj,,,,,,,,,,,
|
32
|
+
,,,,,,,,,,,fffffffffff :ffffffffffffffffffffffff: :ffffffffffffffffffffffff,,,,,,,,,,,
|
33
|
+
,,,,,,,,,,iffffffffff ,jfffffffffffffffffffffffff jfffffffffffffffffffffffffi,,,,,,,,,,
|
34
|
+
,,,,,,,,,,ffffffffffi tffffffffffffffffffffffffff jfffffffffffffff iffffffffff,,,,,,,,,,
|
35
|
+
,,,,,,,,,ifffffffff, jfffffffffffffffffffffffff, jfffffffffffffff ,fffffffffi,,,,,,,,,
|
36
|
+
,,,,,,,,,jfffffffff :ffffffffffffffffffffffffff :fffffffffffffff; fffffffffj,,,,,,,,,
|
37
|
+
,,,,,,,, fffffffffi jffffffffffffffffffffffffff jfffffffffffffff ifffffffff ,,,,,,,,
|
38
|
+
,,,,,,,,ifffffffff tffffffffffffffffffffffffff jfffffffffffffff fffffffffi,,,,,,,,
|
39
|
+
,,,,,,,;fffffffffi :fffffffffffffffffffffffff, jfffffffffffffff ifffffffff;,,,,,,,
|
40
|
+
,,,,,,,ifffffffff: jfffffffffffffffffffffffff :fffffffffffffff; :fffffffffi,,,,,,,
|
41
|
+
,,,,,,,ffffffffff :fffffffffffffffffffffffff jfffffffffffffff ffffffffff,,,,,,,
|
42
|
+
,,,,,,,ffffffffft ,fffffffffffffffff; jfffffffffffffff t, tfffffffff,,,,,,,
|
43
|
+
,,,,,,;fffffffff ffffffffffffffff jfffffffffffffff tff fffffffff;,,,,,,
|
44
|
+
,,,,,,ifffffffft fffffffffffffff, :fffffffffffffff;.fff tffffffffi,,,,,,
|
45
|
+
,,,,,,jffffffff: ;ffffffffffffff. jfffffffffffffff .ffff; :ffffffffj,,,,,,
|
46
|
+
,,,,,,fffffffff ffffffffffffff, jfffffffffffffff tffffff fffffffff,,,,,,
|
47
|
+
,,,,,,fffffffff fffffffffffff jfffffffffffffff tfffffff fffffffff,,,,,,
|
48
|
+
,,,,,,fffffffff fffffffffffff :fffffffffffffff; ........ fffffffff,,,,,,
|
49
|
+
,,,,,;ffffffffj ,ffffffffffff; jfffffffffffffff jffffffff;,,,,,
|
50
|
+
,,,,,;ffffffffi tffffffffffff jfffffffffffffff iffffffff;,,,,,
|
51
|
+
,,,,,;ffffffff; fffffffffffff jfffffffffffffff ;ffffffff;,,,,,
|
52
|
+
,,,,,;ffffffff; fffffffffffff :fffffffffffffff; ;ffffffff;,,,,,
|
53
|
+
,,,,,iffffffff, fffffffffffff jfffffffffffffff ,ffffffffi,,,,,
|
54
|
+
,,,,,iffffffff, fffffffffffff jfffffffffffffff ,ffffffffi,,,,,
|
55
|
+
,,,,,;ffffffff; fffffffffffff jfffffffffffffff ;ffffffff;,,,,,
|
56
|
+
,,,,,;ffffffff; fffffffffffff :fffffffffffffff; ;ffffffff;,,,,,
|
57
|
+
,,,,,;ffffffffi tffffffffffff jfffffffffffffff iffffffff;,,,,,
|
58
|
+
,,,,,;ffffffffj ,fffffffffff jfffffffffffffff jffffffff;,,,,,
|
59
|
+
,,,,,,fffffffff fffffffff, jfffffffffffffff jjjjjjjjjjjjj fffffffff,,,,,,
|
60
|
+
,,,,,,fffffffff fffffffff :fffffffffffffff; .fffffffffffff fffffffff,,,,,,
|
61
|
+
,,,,,,fffffffff ffffffff jfffffffffffffff ,ffffffffffffff fffffffff,,,,,,
|
62
|
+
,,,,,,jffffffff: ;ffffff jfffffffffffffff .ffffffffffffff; :ffffffffj,,,,,,
|
63
|
+
,,,,,,ifffffffft ffff, jfffffffffffffff ,fffffffffffffff tffffffffi,,,,,,
|
64
|
+
,,,,,,;fffffffff ffff :fffffffffffffff; ffffffffffffffff fffffffff;,,,,,,
|
65
|
+
,,,,,,,ffffffffft ,ff jfffffffffffffff ifffffffffffffffff, tfffffffff,,,,,,,
|
66
|
+
,,,,,,,ffffffffff : jfffffffffffffff tfffffffffffffffffffffff: ffffffffff,,,,,,,
|
67
|
+
,,,,,,,ifffffffff: jfffffffffffffff tfffffffffffffffffffffffj :fffffffffi,,,,,,,
|
68
|
+
,,,,,,,;fffffffffi :fffffffffffffff;.ffffffffffffffffffffffff: ifffffffff;,,,,,,,
|
69
|
+
,,,,,,,,ifffffffff jfffffffffffffff .fffffffffffffffffffffffft fffffffffi,,,,,,,,
|
70
|
+
,,,,,,,, fffffffffi jfffffffffffffff tffffffffffffffffffffffffj ifffffffff ,,,,,,,,
|
71
|
+
,,,,,,,,,jfffffffff jfffffffffffffff tffffffffffffffffffffffff: fffffffffj,,,,,,,,,
|
72
|
+
,,,,,,,,,ifffffffff, :fffffffffffffff;.ffffffffffffffffffffffffj ,fffffffffi,,,,,,,,,
|
73
|
+
,,,,,,,,,,ffffffffffi jfffffffffffffff .fffffffffffffffffffffffft iffffffffff,,,,,,,,,,
|
74
|
+
,,,,,,,,,,iffffffffff jfffffffffffffff tfffffffffffffffffffffffj, ffffffffffi,,,,,,,,,,
|
75
|
+
,,,,,,,,,,,ffffffffffffffffffffffffff tfffffffffffffffffffffff: fffffffffff,,,,,,,,,,,
|
76
|
+
,,,,,,,,,,,jffffffffffffffffffffffff; ,ffffffffffffffffffffff, :ffffffffffj,,,,,,,,,,,
|
77
|
+
,,,,,,,,,,,,tffffffffffffffffffffff ;ffffffffffffffff; .fffffffffft,,,,,,,,,,,,
|
78
|
+
,,,,,,,,,,,,,fffffffffffffffffffff ,tfffffft; tfffffffffff,,,,,,,,,,,,,
|
79
|
+
,,,,,,,,,,,,,;fffffffffffffffffff tfffffffffff;,,,,,,,,,,,,,
|
80
|
+
,,,,,,,,,,,,,,ffffffffffffffffff; .ffffffffffff,,,,,,,,,,,,,,
|
81
|
+
,,,,,,,,,,,,,,,ffffffffffffffff :ffffffffffff,,,,,,,,,,,,,,,
|
82
|
+
,,,,,,,,,,,,,,,;jfffffffffffff ffffffffffffj;,,,,,,,,,,,,,,,
|
83
|
+
,,,,,,,,,,,,,,,,,fffffffffffffi ifffffffffffff,,,,,,,,,,,,,,,,,
|
84
|
+
,,,,,,,,,,,,,,,,,ifffffffffffff, ,fffffffffffffi,,,,,,,,,,,,,,,,,
|
85
|
+
,,,,,,,,,,,,,,,,,,tffffffffffffffi ifffffffffffffft,,,,,,,,,,,,,,,,,,
|
86
|
+
,,,,,,,,,,,,,,,,,,,ifffffffffffffffi: :ifffffffffffffffi,,,,,,,,,,,,,,,,,,,
|
87
|
+
,,,,,,,,,,,,,,,,,,,,,jfffffffffffffffft. .tffffffffffffffffj,,,,,,,,,,,,,,,,,,,,,
|
88
|
+
,,,,,,,,,,,,,,,,,,,,,;fffffffffffffffffft: :tffffffffffffffffff;,,,,,,,,,,,,,,,,,,,,,
|
89
|
+
,,,,,,,,,,,,,,,,,,,,,,,ffffffffffffffffffffffjt;;,,;;tjffffffffffffffffffffff,,,,,,,,,,,,,,,,,,,,,,,
|
90
|
+
,,,,,,,,,,,,,,,,,,,,,,,,;ffffffffffffffffffffffffffffffffffffffffffffffffff;,,,,,,,,,,,,,,,,,,,,,,,,
|
91
|
+
,,,,,,,,,,,,,,,,,,,,,,,,,,tfffffffffffffffffffffffffffffffffffffffffffffft,,,,,,,,,,,,,,,,,,,,,,,,,,
|
92
|
+
,,,,,,,,,,,,,,,,,,,,,,,,,,,jffffffffffffffffffffffffffffffffffffffffffffj,,,,,,,,,,,,,,,,,,,,,,,,,,,
|
93
|
+
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,iffffffffffffffffffffffffffffffffffffffffi,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
|
94
|
+
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,ijffffffffffffffffffffffffffffffffffji,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
|
95
|
+
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, iffffffffffffffffffffffffffffffi ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
|
96
|
+
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,;iffffffffffffffffffffffffffi;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
|
97
|
+
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,;ijffffffffffffffffji;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
|
98
|
+
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,;;iiii;;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
|
99
|
+
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
|
100
|
+
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
|
101
|
+
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
|
102
|
+
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
|
103
|
+
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
@@ -0,0 +1,24 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = %q{couchrest_model_config}
|
3
|
+
s.version = File.read "VERSION"
|
4
|
+
|
5
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
6
|
+
s.authors = ["Matt Parker"]
|
7
|
+
s.date = %q{2011-04-26}
|
8
|
+
s.description = %q{Simple, environment-based server and database configuration for couchrest_model.}
|
9
|
+
s.email = %q{moonmaster9000@gmail.com}
|
10
|
+
s.extra_rdoc_files = [
|
11
|
+
"readme.markdown"
|
12
|
+
]
|
13
|
+
|
14
|
+
s.files = `git ls-files`.split("\n")
|
15
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
|
+
|
17
|
+
s.homepage = %q{http://github.com/moonmaster9000/couchrest_model_config}
|
18
|
+
s.require_paths = ["lib"]
|
19
|
+
s.rubygems_version = %q{1.5.0}
|
20
|
+
s.summary = %q{Simple, environment-based server and database configuration for couchrest_model}
|
21
|
+
s.add_dependency(%q<couchrest_model>, ["~> 1.0.0"])
|
22
|
+
s.add_development_dependency(%q<cucumber>, ["~> 0.10.0"])
|
23
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.4.0"])
|
24
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
@db
|
2
|
+
Feature: Configure CouchRest::Model database connections
|
3
|
+
|
4
|
+
Scenario Outline: Configuring the database for a model
|
5
|
+
Given I have a Book model
|
6
|
+
And I have configured databases for 'default', 'production', 'development', and 'test' environments
|
7
|
+
And my app is in the "<environment>" environment
|
8
|
+
When I call CouchRest::Model::Config.Book.current_database
|
9
|
+
Then I should get back the database I cofigured for the "<target>" environment
|
10
|
+
|
11
|
+
Examples:
|
12
|
+
|environment|target|
|
13
|
+
|test|test|
|
14
|
+
|development|development|
|
15
|
+
|production|production|
|
16
|
+
|poo|default|
|
17
|
+
|
18
|
+
Scenario Outline: Configuring the database for a set of models
|
19
|
+
Given I have several models
|
20
|
+
And I set their database via the `database` method
|
21
|
+
And my app is in the "<environment>" environment
|
22
|
+
When I lookup their current_database
|
23
|
+
Then their database should be the one I configured for the "<target>" environment
|
24
|
+
|
25
|
+
Examples:
|
26
|
+
|environment|target|
|
27
|
+
|test|test|
|
28
|
+
|development|development|
|
29
|
+
|production|production|
|
30
|
+
|poo|default|
|
31
|
+
|
32
|
+
Scenario Outline: Configuring the database for a set of models
|
33
|
+
Given I have several models that inherit from a single parent
|
34
|
+
And I configure the parent database via the `database` method
|
35
|
+
And I do not configure the database for the child models
|
36
|
+
And my app is in the "<environment>" environment
|
37
|
+
When I lookup the current_database for the child models
|
38
|
+
Then their database should be the one I configured for the "<target>" environment on the parent
|
39
|
+
|
40
|
+
Examples:
|
41
|
+
|environment|target|
|
42
|
+
|test|test|
|
43
|
+
|development|development|
|
44
|
+
|production|production|
|
45
|
+
|poo|default|
|
46
|
+
|
47
|
+
Scenario Outline: Setting the default database
|
48
|
+
Given I have several models
|
49
|
+
And I configure default databases for all models for the 'test', 'development', 'production', and 'default' environments
|
50
|
+
And I do not configure the database for any specific models
|
51
|
+
And my app is in the "<environment>" environment
|
52
|
+
When I lookup their current_database
|
53
|
+
Then their database should be the one I configured for the "<target>" environment in the default database configuration section
|
54
|
+
|
55
|
+
Examples:
|
56
|
+
|environment|target|
|
57
|
+
|test|test|
|
58
|
+
|development|development|
|
59
|
+
|production|production|
|
60
|
+
|poo|default|
|
61
|
+
|
62
|
+
Scenario: Setting the server while configuring the database
|
63
|
+
When I configure the database for a model
|
64
|
+
Then I should be able to provide the full URI to the database
|
65
|
+
And the database should use the domain provided for the server instead of the default server
|
66
|
+
|
67
|
+
@focus
|
68
|
+
Scenario: Database configured directly on the model takes highest precedence
|
69
|
+
Given I have configured the database for a model directly on the model via `use_database`
|
70
|
+
And I have configured the database for that model via CouchRest::Model::Config
|
71
|
+
When I call the `database` method on the model
|
72
|
+
Then I should receive the database configured directly on the model via `use_database`
|
73
|
+
|
74
|
+
@focus
|
75
|
+
Scenario: Looking up the model's database via the model itself
|
76
|
+
Given I have configured the database for a model via CouchRest::Model::Config
|
77
|
+
When I call the `database` method on the model
|
78
|
+
Then I should receive the database I configured via CouchRest::Model::Config
|
79
|
+
When I call the `database` method on an instance of the model
|
80
|
+
Then I should receive the database I configured via CouchRest::Model::Config
|
@@ -0,0 +1,12 @@
|
|
1
|
+
@environment
|
2
|
+
Feature: Configuring and Retrieving the environment
|
3
|
+
|
4
|
+
Scenario: Environment should default to Rails.env
|
5
|
+
Given Rails.env returns "hi"
|
6
|
+
When I call CouchRest::Model::Config.environment
|
7
|
+
Then I should receive the value of "Rails.env"
|
8
|
+
|
9
|
+
Scenario: Changing the environment detection
|
10
|
+
Given I have configured couchrest_model to detect environment via ENV['RACK_ENV']
|
11
|
+
When I call CouchRest::Model::Config.environment
|
12
|
+
Then I should receive the value of "ENV['RACK_ENV']"
|
@@ -0,0 +1,9 @@
|
|
1
|
+
Feature: Support Namespaced models
|
2
|
+
As an API designer
|
3
|
+
I want to support namespaced models
|
4
|
+
So that I don't look like a fool!
|
5
|
+
|
6
|
+
Scenario: Configuring namespace models
|
7
|
+
Given I have a namespaced model
|
8
|
+
Then I should be able to configure it just like all other models
|
9
|
+
And I should be able to retrieve configuration information about it via the `for` method on CouchRest::Model::Config
|
@@ -0,0 +1,23 @@
|
|
1
|
+
@server
|
2
|
+
Feature: Configure CouchRest::Model database connections
|
3
|
+
|
4
|
+
Scenario: Default CouchRest server
|
5
|
+
When I call CouchRest::Model::Config.server.default
|
6
|
+
Then I should get back a CouchRest server defaulted to host "http://127.0.0.1:5984"
|
7
|
+
|
8
|
+
Scenario: Configuring the CouchRest server
|
9
|
+
When I call CouchRest::Model::Config.edit
|
10
|
+
Then I should be able to pass a block to it that configures the default CouchRest server
|
11
|
+
|
12
|
+
Scenario Outline: Getting the appropriate server
|
13
|
+
Given I have configured servers for 'default', 'production', 'development', and 'test' environments
|
14
|
+
And my app is in the "<environment>" environment
|
15
|
+
When I call CouchRest::Model::Config.current_server
|
16
|
+
Then I should get back the server I configured for the "<target>" environment
|
17
|
+
|
18
|
+
Examples:
|
19
|
+
|environment|target|
|
20
|
+
|test|test|
|
21
|
+
|development|development|
|
22
|
+
|production|production|
|
23
|
+
|poo|default|
|
@@ -0,0 +1,223 @@
|
|
1
|
+
When /^I call CouchRest::Model::Config\.server\.default$/ do
|
2
|
+
@default_server = CouchRest::Model::Config.server.default
|
3
|
+
end
|
4
|
+
|
5
|
+
Then /^I should be able to pass a block to it that configures the default CouchRest server$/ do
|
6
|
+
CouchRest::Model::Config.edit do
|
7
|
+
server do
|
8
|
+
default "http://localhost:5984"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
Given /^I have configured servers for 'default', 'production', 'development', and 'test' environments$/ do
|
14
|
+
CouchRest::Model::Config.edit do
|
15
|
+
server do
|
16
|
+
default "http://default:5984"
|
17
|
+
production "http://production:5984"
|
18
|
+
development "http://development:5984"
|
19
|
+
test "http://test:5984"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
Given /^my app is in the "([^"]*)" environment$/ do |env|
|
25
|
+
CouchRest::Model::Config.edit do
|
26
|
+
environment do
|
27
|
+
env
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
When /^I call CouchRest::Model::Config\.current_server$/ do
|
33
|
+
@current_server = CouchRest::Model::Config.current_server
|
34
|
+
end
|
35
|
+
|
36
|
+
Then /^I should get back the server I configured for the "([^"]*)" environment$/ do |env|
|
37
|
+
@current_server.uri.should == "http://#{env}:5984"
|
38
|
+
end
|
39
|
+
|
40
|
+
Then /^I should get back a CouchRest server defaulted to host "([^"]*)"$/ do |host_uri|
|
41
|
+
@default_server.uri.should == host_uri
|
42
|
+
end
|
43
|
+
|
44
|
+
When /^I call CouchRest::Model::Config\.edit$/ do
|
45
|
+
end
|
46
|
+
|
47
|
+
Given /^I have a Book model$/ do
|
48
|
+
class Book < CouchRest::Model::Base; end
|
49
|
+
end
|
50
|
+
|
51
|
+
Given /^I have configured databases for 'default', 'production', 'development', and 'test' environments$/ do
|
52
|
+
CouchRest::Model::Config.edit do
|
53
|
+
database Book do
|
54
|
+
default "book_default_db"
|
55
|
+
production "book_production_db"
|
56
|
+
development "book_development_db"
|
57
|
+
test "book_test_db"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
When /^I call CouchRest::Model::Config\.Book\.current_database$/ do
|
63
|
+
@current_database = CouchRest::Model::Config.Book.current_database
|
64
|
+
end
|
65
|
+
|
66
|
+
Then /^I should get back the database I cofigured for the "([^"]*)" environment$/ do |env|
|
67
|
+
@current_database.name.should == "book_#{env}_db"
|
68
|
+
end
|
69
|
+
|
70
|
+
Given /^I have several models$/ do
|
71
|
+
class Models1 < CouchRest::Model::Base; end
|
72
|
+
class Models2 < CouchRest::Model::Base; end
|
73
|
+
class Models3 < CouchRest::Model::Base; end
|
74
|
+
class Models4 < CouchRest::Model::Base; end
|
75
|
+
end
|
76
|
+
|
77
|
+
Given /^I set their database via the `database` method$/ do
|
78
|
+
CouchRest::Model::Config.edit do
|
79
|
+
database Models1, Models2, Models3, Models4 do
|
80
|
+
default "default_db"
|
81
|
+
test "test_db"
|
82
|
+
development "development_db"
|
83
|
+
production "production_db"
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
When /^I lookup their current_database$/ do
|
89
|
+
@dbs = (1..4).to_a.map {|i| CouchRest::Model::Config.send("Models#{i}").current_database}
|
90
|
+
end
|
91
|
+
|
92
|
+
Then /^their database should be the one I configured for the "([^"]*)" environment$/ do |env|
|
93
|
+
@dbs.all? {|db| db.name == "#{env}_db"}.should be_true
|
94
|
+
end
|
95
|
+
|
96
|
+
Given /^I have several models that inherit from a single parent$/ do
|
97
|
+
class ParentModel < CouchRest::Model::Base; end
|
98
|
+
class ChildModel1 < ParentModel; end
|
99
|
+
class ChildModel2 < ParentModel; end
|
100
|
+
class ChildModel3 < ParentModel; end
|
101
|
+
class ChildModel4 < ParentModel; end
|
102
|
+
end
|
103
|
+
|
104
|
+
Given /^I configure the parent database via the `database` method$/ do
|
105
|
+
CouchRest::Model::Config.edit do
|
106
|
+
database ParentModel do
|
107
|
+
default "default_db"
|
108
|
+
production "production_db"
|
109
|
+
development "development_db"
|
110
|
+
test "test_db"
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
Given /^I do not configure the database for the child models$/ do
|
116
|
+
end
|
117
|
+
|
118
|
+
When /^I lookup the current_database for the child models$/ do
|
119
|
+
@dbs = (1..4).to_a.map {|i| CouchRest::Model::Config.send("ChildModel#{i}").current_database}
|
120
|
+
end
|
121
|
+
|
122
|
+
Then /^their database should be the one I configured for the "([^"]*)" environment on the parent$/ do |env|
|
123
|
+
@dbs.all? {|db| db.name == "#{env}_db"}.should be_true
|
124
|
+
end
|
125
|
+
|
126
|
+
Given /^I configure default databases for all models for the 'test', 'development', 'production', and 'default' environments$/ do
|
127
|
+
CouchRest::Model::Config.edit do
|
128
|
+
database do
|
129
|
+
default "default_db"
|
130
|
+
production "production_db"
|
131
|
+
development "development_db"
|
132
|
+
test "test_db"
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
Given /^I do not configure the database for any specific models$/ do
|
138
|
+
end
|
139
|
+
|
140
|
+
Then /^their database should be the one I configured for the "([^"]*)" environment in the default database configuration section$/ do |env|
|
141
|
+
@dbs.all? {|db| db.name == "#{env}_db"}.should be_true
|
142
|
+
end
|
143
|
+
|
144
|
+
Given /^I have a namespaced model$/ do
|
145
|
+
module ConfigTest
|
146
|
+
class Model < CouchRest::Model::Base; end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
Then /^I should be able to configure it just like all other models$/ do
|
151
|
+
CouchRest::Model::Config.edit do
|
152
|
+
database ConfigTest::Model do
|
153
|
+
production "config_test_model_production"
|
154
|
+
default "config_test_model_default"
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
Then /^I should be able to retrieve configuration information about it via the `for` method on CouchRest::Model::Config$/ do
|
160
|
+
CouchRest::Model::Config.for(ConfigTest::Model).production.name.should == "config_test_model_production"
|
161
|
+
CouchRest::Model::Config.for(ConfigTest::Model).default.name.should == "config_test_model_default"
|
162
|
+
CouchRest::Model::Config.for(ConfigTest::Model).test.should be_nil
|
163
|
+
end
|
164
|
+
|
165
|
+
When /^I configure the database for a model$/ do
|
166
|
+
class ModelWithCustomServer < CouchRest::Model::Base; end
|
167
|
+
end
|
168
|
+
|
169
|
+
Then /^I should be able to provide the full URI to the database$/ do
|
170
|
+
CouchRest::Model::Config.edit do
|
171
|
+
database ModelWithCustomServer do
|
172
|
+
default "http://my.custom.server.com/model_db"
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
Then /^the database should use the domain provided for the server instead of the default server$/ do
|
178
|
+
CouchRest::Model::Config.ModelWithCustomServer.default.name.should == "model_db"
|
179
|
+
CouchRest::Model::Config.ModelWithCustomServer.default.server.uri.should == "http://my.custom.server.com"
|
180
|
+
end
|
181
|
+
|
182
|
+
Given /^I have configured the database for a model directly on the model via `use_database`$/ do
|
183
|
+
server = CouchRest.new
|
184
|
+
DIRECTLY_CONFIGURED_MODEL_DB = server.database! "directly_configured_model_database"
|
185
|
+
class DirectlyConfiguredModel < CouchRest::Model::Base
|
186
|
+
use_database DIRECTLY_CONFIGURED_MODEL_DB
|
187
|
+
end
|
188
|
+
@model = DirectlyConfiguredModel
|
189
|
+
end
|
190
|
+
|
191
|
+
Given /^I have configured the database for that model via CouchRest::Model::Config$/ do
|
192
|
+
CouchRest::Model::Config.edit do
|
193
|
+
database DirectlyConfiguredModel do
|
194
|
+
default "indirectly_configured_db"
|
195
|
+
end
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
When /^I call the `database` method on the model$/ do
|
200
|
+
@model_database = @model.database
|
201
|
+
end
|
202
|
+
|
203
|
+
Then /^I should receive the database configured directly on the model via `use_database`$/ do
|
204
|
+
@model_database.name.should == "directly_configured_model_database"
|
205
|
+
end
|
206
|
+
|
207
|
+
Given /^I have configured the database for a model via CouchRest::Model::Config$/ do
|
208
|
+
class IndirectlyConfiguredModel < CouchRest::Model::Base; end
|
209
|
+
CouchRest::Model::Config.edit do
|
210
|
+
database IndirectlyConfiguredModel do
|
211
|
+
default "indirect_db"
|
212
|
+
end
|
213
|
+
end
|
214
|
+
@model = IndirectlyConfiguredModel
|
215
|
+
end
|
216
|
+
|
217
|
+
Then /^I should receive the database I configured via CouchRest::Model::Config$/ do
|
218
|
+
@model_database.name.should == "indirect_db"
|
219
|
+
end
|
220
|
+
|
221
|
+
When /^I call the `database` method on an instance of the model$/ do
|
222
|
+
@model_database = IndirectlyConfiguredModel.new.database
|
223
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
Given /^Rails\.env returns "([^"]*)"$/ do |rails_env|
|
2
|
+
unless defined? Rails
|
3
|
+
Rails = double "Rails"
|
4
|
+
end
|
5
|
+
Rails.stub(:env).and_return rails_env
|
6
|
+
Rails.env.should == rails_env
|
7
|
+
end
|
8
|
+
|
9
|
+
When /^I call CouchRest::Model::Config\.environment$/ do
|
10
|
+
@env = CouchRest::Model::Config.environment
|
11
|
+
end
|
12
|
+
|
13
|
+
Then /^I should receive the value of "([^"]*)"$/ do |eval_this|
|
14
|
+
@env.should == eval(eval_this)
|
15
|
+
end
|
16
|
+
|
17
|
+
Given /^I have configured couchrest_model to detect environment via ENV\['RACK_ENV'\]$/ do
|
18
|
+
ENV['RACK_ENV'] = 'matt did this!'
|
19
|
+
CouchRest::Model::Config.edit do
|
20
|
+
environment do
|
21
|
+
ENV['RACK_ENV']
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
Given /^I have configured CouchRest::Model via CouchRest::Model::Config$/ do
|
2
|
+
class Book < CouchRest::Model::Base; end
|
3
|
+
CouchRest::Model::Config.edit do
|
4
|
+
database Book do
|
5
|
+
default "book_db"
|
6
|
+
end
|
7
|
+
|
8
|
+
environment do
|
9
|
+
"haha"
|
10
|
+
end
|
11
|
+
|
12
|
+
server do
|
13
|
+
default "http://poo.com"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
CouchRest::Model::Config.Book.default.class.should == CouchRest::Database
|
17
|
+
CouchRest::Model::Config.Book.default.name.should == "book_db"
|
18
|
+
CouchRest::Model::Config.server.default.uri.should == "http://poo.com"
|
19
|
+
CouchRest::Model::Config.environment.should == "haha"
|
20
|
+
end
|
21
|
+
|
22
|
+
When /^I call the reset method$/ do
|
23
|
+
CouchRest::Model::Config.reset
|
24
|
+
end
|
25
|
+
|
26
|
+
Then /^CouchRest::Model::Config should be reset to defaults$/ do
|
27
|
+
unless defined? Rails
|
28
|
+
Rails = double "Rails"
|
29
|
+
end
|
30
|
+
Rails.stub(:env).and_return "matt"
|
31
|
+
CouchRest::Model::Config.Book.all.should be_nil
|
32
|
+
CouchRest::Model::Config.Book.default.should be_nil
|
33
|
+
CouchRest::Model::Config.server.default.uri.should == "http://127.0.0.1:5984"
|
34
|
+
CouchRest::Model::Config.environment.should == "matt"
|
35
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
module CouchRest
|
2
|
+
module Model
|
3
|
+
module Config
|
4
|
+
extend self
|
5
|
+
|
6
|
+
def environment(&block)
|
7
|
+
block ? environment_proc(block) : environment_proc.call
|
8
|
+
end
|
9
|
+
|
10
|
+
def current_server
|
11
|
+
Server.send(environment) || Server.default
|
12
|
+
end
|
13
|
+
|
14
|
+
def server(&block)
|
15
|
+
block ? Server.instance_eval(&block) : Server
|
16
|
+
end
|
17
|
+
|
18
|
+
def edit(&block)
|
19
|
+
self.instance_eval &block
|
20
|
+
end
|
21
|
+
|
22
|
+
def database(*args, &block)
|
23
|
+
if args.empty?
|
24
|
+
configure_default_database &block
|
25
|
+
else
|
26
|
+
args.each {|m| configure_model m, &block}
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def reset
|
31
|
+
@model_configs = {}
|
32
|
+
@environment_proc = nil
|
33
|
+
Server.reset
|
34
|
+
end
|
35
|
+
|
36
|
+
def default_database
|
37
|
+
model_configs(:default_database).send(self.environment) || model_configs(:default_database).default
|
38
|
+
end
|
39
|
+
|
40
|
+
def for(m)
|
41
|
+
m = m.to_s.camelize.constantize unless m.class == Class
|
42
|
+
model_configs(m)
|
43
|
+
end
|
44
|
+
|
45
|
+
def method_missing(model, *args, &block)
|
46
|
+
model = model.to_s.camelize.constantize
|
47
|
+
return model_configs(model) unless block
|
48
|
+
configure_model model, &block
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
def environment_proc(p=nil)
|
53
|
+
if p.nil?
|
54
|
+
@environment_proc ||= proc { Rails.env }
|
55
|
+
else
|
56
|
+
@environment_proc = p
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def configure_model(model, &block)
|
61
|
+
model_configs(model).instance_eval &block
|
62
|
+
end
|
63
|
+
|
64
|
+
def model_configs(model=nil)
|
65
|
+
@model_configs ||= {}
|
66
|
+
return (@model_configs[model] ||= Model.new model) if model
|
67
|
+
end
|
68
|
+
|
69
|
+
def configure_default_database(&block)
|
70
|
+
model_configs(:default_database).instance_eval &block
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module CouchRest
|
2
|
+
module Model
|
3
|
+
class Base
|
4
|
+
class << self
|
5
|
+
def database_with_couchrest_model_config
|
6
|
+
database_without_couchrest_model_config || CouchRest::Model::Config.for(self).current_database
|
7
|
+
end
|
8
|
+
|
9
|
+
alias_method_chain :database, :couchrest_model_config
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module CouchRest
|
2
|
+
module Model
|
3
|
+
module Config
|
4
|
+
class Model
|
5
|
+
attr_reader :environments
|
6
|
+
|
7
|
+
def initialize(klass)
|
8
|
+
@klass = klass
|
9
|
+
@environments = {}
|
10
|
+
end
|
11
|
+
|
12
|
+
def test(db=nil)
|
13
|
+
if db.nil?
|
14
|
+
@environments[:test]
|
15
|
+
else
|
16
|
+
@environments[:test] = CouchRest::Model::Config.current_server.database! db
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def current_database
|
21
|
+
configured_model_database ||
|
22
|
+
configured_ancestor_database ||
|
23
|
+
CouchRest::Model::Config.default_database
|
24
|
+
end
|
25
|
+
|
26
|
+
def method_missing(environment, *args, &block)
|
27
|
+
return @environments[environment] if args.length == 0
|
28
|
+
couch_server, database = parse_database_config args.first
|
29
|
+
@environments[environment] = couch_server.database! database
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
def parse_database_config(db)
|
34
|
+
if db.match(%r{^(https?://.*)/(.*)$})
|
35
|
+
[CouchRest.new($1), $2]
|
36
|
+
else
|
37
|
+
[CouchRest::Model::Config.current_server, db]
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def configured_model_database
|
42
|
+
@environments[current_env] || @environments[:default]
|
43
|
+
end
|
44
|
+
|
45
|
+
def configured_ancestor_database
|
46
|
+
db = nil
|
47
|
+
@klass.ancestors.each do |a|
|
48
|
+
db ||=
|
49
|
+
CouchRest::Model::Config.for(a).send(current_env) ||
|
50
|
+
CouchRest::Model::Config.for(a).default
|
51
|
+
end
|
52
|
+
db
|
53
|
+
end
|
54
|
+
|
55
|
+
def current_env
|
56
|
+
current_env = CouchRest::Model::Config.environment.to_sym
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module CouchRest
|
2
|
+
module Model
|
3
|
+
module Config
|
4
|
+
module Server
|
5
|
+
extend self
|
6
|
+
|
7
|
+
def reset
|
8
|
+
@environments = {}
|
9
|
+
end
|
10
|
+
|
11
|
+
def default(uri=nil)
|
12
|
+
if uri.nil?
|
13
|
+
environments[:default] ||= CouchRest.new
|
14
|
+
else
|
15
|
+
environments[:default] = CouchRest.new uri
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def test(uri=nil)
|
20
|
+
if uri.nil?
|
21
|
+
environments[:test]
|
22
|
+
else
|
23
|
+
environments[:test] = CouchRest.new uri
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def method_missing(environment, *args, &block)
|
28
|
+
case args.length
|
29
|
+
when 0 then environments[environment]
|
30
|
+
when 1 then environments[environment] = CouchRest.new args.first
|
31
|
+
else raise "Too many arguments passed to the '#{environment}' server configuration!"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
def environments
|
37
|
+
@environments ||= {}
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/readme.markdown
ADDED
@@ -0,0 +1,153 @@
|
|
1
|
+
# CouchRest::Model::Config
|
2
|
+
|
3
|
+
Simple environment-based CouchRest::Model configuration. Suitable for Rails, Sinatra, Rack, whatev.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Install the gem `couchrest_model_config` however you see fit to do so. Then `require 'couchrest_model_config'`.
|
8
|
+
|
9
|
+
## Configuring environment detection
|
10
|
+
|
11
|
+
By default, CouchRest::Model::Config assumes a Rails 3 app, and will detect your app's environment via `Rails.env`. If you're using this in something other than a Rails 3 app,
|
12
|
+
then simply override the default environment detection:
|
13
|
+
|
14
|
+
# Sinatra example
|
15
|
+
CouchRest::Model::Config.edit do
|
16
|
+
environment do
|
17
|
+
settings.environment
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# Rack example
|
22
|
+
CouchRest::Model::Config.edit do
|
23
|
+
environment do
|
24
|
+
ENV['RACK_ENV'] || 'development'
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
## Configuring the default database
|
29
|
+
|
30
|
+
Suppose you want all of your couchrest models to use the same database in your application. No problem! You can use the `database` configuration method without
|
31
|
+
any arguments:
|
32
|
+
|
33
|
+
CouchRest::Model::Config.edit do
|
34
|
+
database do
|
35
|
+
default "my_db_#{Rails.env}"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
This means that the default database name for all of your models will be "my_db_" followed by your Rails environment.
|
40
|
+
|
41
|
+
You could customize the database names per environment further:
|
42
|
+
|
43
|
+
CouchRest::Model::Config.edit do
|
44
|
+
database do
|
45
|
+
default "my_db_#{Rails.env}"
|
46
|
+
production "my_production_db"
|
47
|
+
test "funny_test_db_name"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
For any environment not explicitly configured, it will fall back to the database name.
|
52
|
+
|
53
|
+
## Configuring the database for a model
|
54
|
+
|
55
|
+
To set the database for a model, use the `database` method. For example, suppose we'd like to set the database name for our `Book` model to
|
56
|
+
`library` in all environments:
|
57
|
+
|
58
|
+
CouchRest::Model::Config.edit do
|
59
|
+
database Book do
|
60
|
+
default "library"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
Or, perhaps we'd like to differentiate the name between production, development, and test environments:
|
65
|
+
|
66
|
+
CouchRest::Model::Config.edit do
|
67
|
+
database Book do
|
68
|
+
production "library_production"
|
69
|
+
development "library_development"
|
70
|
+
test "library_test"
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
In a Rails app, this could be simplified to:
|
75
|
+
|
76
|
+
CouchRest::Model::Config.edit do
|
77
|
+
database Book do
|
78
|
+
default "library_#{Rails.env}"
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
## Configuring the database for a set of models
|
83
|
+
|
84
|
+
Similarly, you could set the database for a whole set of models in one of two ways:
|
85
|
+
|
86
|
+
1. Make every model inherit from the same parent (or mixin the same module), and set the parent's database via the `database` method
|
87
|
+
2. Pass several models to the `database` method
|
88
|
+
|
89
|
+
### Inheritance / Mixins
|
90
|
+
|
91
|
+
Let's imagine that our `Book`, `Author`, and `Genre` models all mixed in the `Library` module:
|
92
|
+
|
93
|
+
module Library; end
|
94
|
+
class Book < CouchRest::Model::Base; include Library; end
|
95
|
+
class Author < CouchRest::Model::Base; include Library; end
|
96
|
+
class Genre < CouchRest::Model::Base; include Library; end
|
97
|
+
|
98
|
+
To make the `Book`, `Author`, and `Genre` models use the same database, simply set the `Library` database in the config:
|
99
|
+
|
100
|
+
CouchRest::Model::Config.edit do
|
101
|
+
database Library do
|
102
|
+
default "library"
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
Now, the database for `Book`, `Author`, and `Genre` will all be set to the same database, "library".
|
107
|
+
|
108
|
+
### Passing several models to the `database` method
|
109
|
+
|
110
|
+
Suppose `Book`, `Author`, and `Genre` couldn't all inherit from the same parent class, yet we'd still like all of them to share the same database;
|
111
|
+
then we could simply pass all of the models to the `database` method:
|
112
|
+
|
113
|
+
CouchRest::Model::Config.edit do
|
114
|
+
database Book, Author, Genre do
|
115
|
+
default "library"
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
## Configuring the CouchDB server
|
120
|
+
|
121
|
+
Without any configuration, CouchRest::Model::Config will assume a CouchDB server at "http://127.0.0.1:5984".
|
122
|
+
|
123
|
+
If you'd like to set a default server for all models regardless of environment, then try:
|
124
|
+
|
125
|
+
CouchRest::Model::Config.edit do
|
126
|
+
server do
|
127
|
+
default "http://admin:password@localhost:5984"
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
If you wanted to change the server to be different in the `production` environment:
|
132
|
+
|
133
|
+
CouchRest::Model::Config.edit do
|
134
|
+
server do
|
135
|
+
default "http://admin:password@localhost:5984"
|
136
|
+
production "https://root:blah@my.production.server:5984"
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
Now, in the production environment, it will connect to CouchDB server `my.production.server`; in all other environments, it will connect to `localhost`.
|
141
|
+
|
142
|
+
If you'd like to change the CouchDB server for a specific model or set of models, simply set the database name for the model (or models) to the entire
|
143
|
+
CouchDB uri for the database:
|
144
|
+
|
145
|
+
CouchRest::Model::Config.edit do
|
146
|
+
database Blog do
|
147
|
+
default "http://localhost:5984/blog"
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
## LICENSE
|
152
|
+
|
153
|
+
There is no license. Why? Because this software has been committed to the public domain. DO ANYTHING WITH IT!!!
|
metadata
ADDED
@@ -0,0 +1,145 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: couchrest_model_config
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Matt Parker
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-04-26 00:00:00 -04:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: couchrest_model
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 23
|
30
|
+
segments:
|
31
|
+
- 1
|
32
|
+
- 0
|
33
|
+
- 0
|
34
|
+
version: 1.0.0
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: cucumber
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 55
|
46
|
+
segments:
|
47
|
+
- 0
|
48
|
+
- 10
|
49
|
+
- 0
|
50
|
+
version: 0.10.0
|
51
|
+
type: :development
|
52
|
+
version_requirements: *id002
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: rspec
|
55
|
+
prerelease: false
|
56
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
hash: 31
|
62
|
+
segments:
|
63
|
+
- 2
|
64
|
+
- 4
|
65
|
+
- 0
|
66
|
+
version: 2.4.0
|
67
|
+
type: :development
|
68
|
+
version_requirements: *id003
|
69
|
+
description: Simple, environment-based server and database configuration for couchrest_model.
|
70
|
+
email: moonmaster9000@gmail.com
|
71
|
+
executables: []
|
72
|
+
|
73
|
+
extensions: []
|
74
|
+
|
75
|
+
extra_rdoc_files:
|
76
|
+
- readme.markdown
|
77
|
+
files:
|
78
|
+
- .gitignore
|
79
|
+
- .rvmrc
|
80
|
+
- Gemfile
|
81
|
+
- Gemfile.lock
|
82
|
+
- PUBLIC_DOMAIN
|
83
|
+
- VERSION
|
84
|
+
- couchrest_model_config.gemspec
|
85
|
+
- features/configure_database.feature
|
86
|
+
- features/configure_environment.feature
|
87
|
+
- features/configure_namespace_model.feature
|
88
|
+
- features/configure_server.feature
|
89
|
+
- features/reset.feature
|
90
|
+
- features/step_definitions/configure_steps.rb
|
91
|
+
- features/step_definitions/environment_steps.rb
|
92
|
+
- features/step_definitions/reset_steps.rb
|
93
|
+
- features/support/env.rb
|
94
|
+
- features/support/hooks.rb
|
95
|
+
- lib/couchrest_model_config.rb
|
96
|
+
- lib/couchrest_model_config/config.rb
|
97
|
+
- lib/couchrest_model_config/couchrest_model_base.rb
|
98
|
+
- lib/couchrest_model_config/model.rb
|
99
|
+
- lib/couchrest_model_config/server.rb
|
100
|
+
- readme.markdown
|
101
|
+
has_rdoc: true
|
102
|
+
homepage: http://github.com/moonmaster9000/couchrest_model_config
|
103
|
+
licenses: []
|
104
|
+
|
105
|
+
post_install_message:
|
106
|
+
rdoc_options: []
|
107
|
+
|
108
|
+
require_paths:
|
109
|
+
- lib
|
110
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
111
|
+
none: false
|
112
|
+
requirements:
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
hash: 3
|
116
|
+
segments:
|
117
|
+
- 0
|
118
|
+
version: "0"
|
119
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
120
|
+
none: false
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
hash: 3
|
125
|
+
segments:
|
126
|
+
- 0
|
127
|
+
version: "0"
|
128
|
+
requirements: []
|
129
|
+
|
130
|
+
rubyforge_project:
|
131
|
+
rubygems_version: 1.6.2
|
132
|
+
signing_key:
|
133
|
+
specification_version: 3
|
134
|
+
summary: Simple, environment-based server and database configuration for couchrest_model
|
135
|
+
test_files:
|
136
|
+
- features/configure_database.feature
|
137
|
+
- features/configure_environment.feature
|
138
|
+
- features/configure_namespace_model.feature
|
139
|
+
- features/configure_server.feature
|
140
|
+
- features/reset.feature
|
141
|
+
- features/step_definitions/configure_steps.rb
|
142
|
+
- features/step_definitions/environment_steps.rb
|
143
|
+
- features/step_definitions/reset_steps.rb
|
144
|
+
- features/support/env.rb
|
145
|
+
- features/support/hooks.rb
|