couchrest_model_config 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.rvmrc +1 -1
- data/CHANGELOG +3 -0
- data/Gemfile.lock +2 -2
- data/VERSION +1 -1
- data/lib/couchrest_model_config/couchrest_model_base.rb +6 -0
- data/readme.markdown +97 -73
- metadata +4 -3
data/.rvmrc
CHANGED
@@ -1 +1 @@
|
|
1
|
-
rvm
|
1
|
+
rvm 1.8.7@couchrest_model_config --create
|
data/CHANGELOG
ADDED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
|
4
|
+
couchrest_model_config (0.0.1)
|
5
5
|
couchrest_model (~> 1.0.0)
|
6
6
|
|
7
7
|
GEM
|
@@ -78,6 +78,6 @@ PLATFORMS
|
|
78
78
|
ruby
|
79
79
|
|
80
80
|
DEPENDENCIES
|
81
|
-
|
81
|
+
couchrest_model_config!
|
82
82
|
cucumber (~> 0.10.0)
|
83
83
|
rspec (~> 2.4.0)
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.2
|
@@ -8,6 +8,12 @@ module CouchRest
|
|
8
8
|
|
9
9
|
alias_method_chain :database, :couchrest_model_config
|
10
10
|
end
|
11
|
+
|
12
|
+
def database_with_couchrest_model_config
|
13
|
+
database_without_couchrest_model_config || CouchRest::Model::Config.for(self.class).current_database
|
14
|
+
end
|
15
|
+
|
16
|
+
alias_method_chain :database, :couchrest_model_config
|
11
17
|
end
|
12
18
|
end
|
13
19
|
end
|
data/readme.markdown
CHANGED
@@ -10,43 +10,49 @@ Install the gem `couchrest_model_config` however you see fit to do so. Then `req
|
|
10
10
|
|
11
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
12
|
then simply override the default environment detection:
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
# Sinatra example
|
16
|
+
CouchRest::Model::Config.edit do
|
17
|
+
environment do
|
18
|
+
settings.environment
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# Rack example
|
23
|
+
CouchRest::Model::Config.edit do
|
24
|
+
environment do
|
25
|
+
ENV['RACK_ENV'] || 'development'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
```
|
27
29
|
|
28
30
|
## Configuring the default database
|
29
31
|
|
30
32
|
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
33
|
any arguments:
|
32
34
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
35
|
+
```ruby
|
36
|
+
CouchRest::Model::Config.edit do
|
37
|
+
database do
|
38
|
+
default "my_db_#{Rails.env}"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
```
|
38
42
|
|
39
43
|
This means that the default database name for all of your models will be "my_db_" followed by your Rails environment.
|
40
44
|
|
41
45
|
You could customize the database names per environment further:
|
42
46
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
47
|
+
```ruby
|
48
|
+
CouchRest::Model::Config.edit do
|
49
|
+
database do
|
50
|
+
default "my_db_#{Rails.env}"
|
51
|
+
production "my_production_db"
|
52
|
+
test "funny_test_db_name"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
```
|
50
56
|
|
51
57
|
For any environment not explicitly configured, it will fall back to the database name.
|
52
58
|
|
@@ -55,29 +61,35 @@ For any environment not explicitly configured, it will fall back to the database
|
|
55
61
|
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
62
|
`library` in all environments:
|
57
63
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
64
|
+
```ruby
|
65
|
+
CouchRest::Model::Config.edit do
|
66
|
+
database Book do
|
67
|
+
default "library"
|
68
|
+
end
|
69
|
+
end
|
70
|
+
```
|
63
71
|
|
64
72
|
Or, perhaps we'd like to differentiate the name between production, development, and test environments:
|
65
73
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
74
|
+
```ruby
|
75
|
+
CouchRest::Model::Config.edit do
|
76
|
+
database Book do
|
77
|
+
production "library_production"
|
78
|
+
development "library_development"
|
79
|
+
test "library_test"
|
80
|
+
end
|
81
|
+
end
|
82
|
+
```
|
73
83
|
|
74
84
|
In a Rails app, this could be simplified to:
|
75
85
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
86
|
+
```ruby
|
87
|
+
CouchRest::Model::Config.edit do
|
88
|
+
database Book do
|
89
|
+
default "library_#{Rails.env}"
|
90
|
+
end
|
91
|
+
end
|
92
|
+
```
|
81
93
|
|
82
94
|
## Configuring the database for a set of models
|
83
95
|
|
@@ -90,18 +102,22 @@ Similarly, you could set the database for a whole set of models in one of two wa
|
|
90
102
|
|
91
103
|
Let's imagine that our `Book`, `Author`, and `Genre` models all mixed in the `Library` module:
|
92
104
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
105
|
+
```ruby
|
106
|
+
module Library; end
|
107
|
+
class Book < CouchRest::Model::Base; include Library; end
|
108
|
+
class Author < CouchRest::Model::Base; include Library; end
|
109
|
+
class Genre < CouchRest::Model::Base; include Library; end
|
110
|
+
```
|
97
111
|
|
98
112
|
To make the `Book`, `Author`, and `Genre` models use the same database, simply set the `Library` database in the config:
|
99
113
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
114
|
+
```ruby
|
115
|
+
CouchRest::Model::Config.edit do
|
116
|
+
database Library do
|
117
|
+
default "library"
|
118
|
+
end
|
119
|
+
end
|
120
|
+
```
|
105
121
|
|
106
122
|
Now, the database for `Book`, `Author`, and `Genre` will all be set to the same database, "library".
|
107
123
|
|
@@ -110,11 +126,13 @@ Now, the database for `Book`, `Author`, and `Genre` will all be set to the same
|
|
110
126
|
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
127
|
then we could simply pass all of the models to the `database` method:
|
112
128
|
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
129
|
+
```ruby
|
130
|
+
CouchRest::Model::Config.edit do
|
131
|
+
database Book, Author, Genre do
|
132
|
+
default "library"
|
133
|
+
end
|
134
|
+
end
|
135
|
+
```
|
118
136
|
|
119
137
|
## Configuring the CouchDB server
|
120
138
|
|
@@ -122,31 +140,37 @@ Without any configuration, CouchRest::Model::Config will assume a CouchDB server
|
|
122
140
|
|
123
141
|
If you'd like to set a default server for all models regardless of environment, then try:
|
124
142
|
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
143
|
+
```ruby
|
144
|
+
CouchRest::Model::Config.edit do
|
145
|
+
server do
|
146
|
+
default "http://admin:password@localhost:5984"
|
147
|
+
end
|
148
|
+
end
|
149
|
+
```
|
130
150
|
|
131
151
|
If you wanted to change the server to be different in the `production` environment:
|
132
152
|
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
153
|
+
```ruby
|
154
|
+
CouchRest::Model::Config.edit do
|
155
|
+
server do
|
156
|
+
default "http://admin:password@localhost:5984"
|
157
|
+
production "https://root:blah@my.production.server:5984"
|
158
|
+
end
|
159
|
+
end
|
160
|
+
```
|
139
161
|
|
140
162
|
Now, in the production environment, it will connect to CouchDB server `my.production.server`; in all other environments, it will connect to `localhost`.
|
141
163
|
|
142
164
|
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
165
|
CouchDB uri for the database:
|
144
166
|
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
167
|
+
```ruby
|
168
|
+
CouchRest::Model::Config.edit do
|
169
|
+
database Blog do
|
170
|
+
default "http://localhost:5984/blog"
|
171
|
+
end
|
172
|
+
end
|
173
|
+
```
|
150
174
|
|
151
175
|
## LICENSE
|
152
176
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: couchrest_model_config
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Matt Parker
|
@@ -77,6 +77,7 @@ extra_rdoc_files:
|
|
77
77
|
files:
|
78
78
|
- .gitignore
|
79
79
|
- .rvmrc
|
80
|
+
- CHANGELOG
|
80
81
|
- Gemfile
|
81
82
|
- Gemfile.lock
|
82
83
|
- PUBLIC_DOMAIN
|