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 CHANGED
@@ -1 +1 @@
1
- rvm gemset use couchrest_model_database_config
1
+ rvm 1.8.7@couchrest_model_config --create
data/CHANGELOG ADDED
@@ -0,0 +1,3 @@
1
+ v0.0.2
2
+ -- alias_method_chain both the class and instance `database` methods
3
+ on CouchRest::Model::Base
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- couchrest_model_database_config (0.0.0)
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
- couchrest_model_database_config!
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
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
- # 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
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
- CouchRest::Model::Config.edit do
34
- database do
35
- default "my_db_#{Rails.env}"
36
- end
37
- end
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
- 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
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
- CouchRest::Model::Config.edit do
59
- database Book do
60
- default "library"
61
- end
62
- end
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
- 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
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
- CouchRest::Model::Config.edit do
77
- database Book do
78
- default "library_#{Rails.env}"
79
- end
80
- end
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
- 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
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
- CouchRest::Model::Config.edit do
101
- database Library do
102
- default "library"
103
- end
104
- end
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
- CouchRest::Model::Config.edit do
114
- database Book, Author, Genre do
115
- default "library"
116
- end
117
- end
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
- CouchRest::Model::Config.edit do
126
- server do
127
- default "http://admin:password@localhost:5984"
128
- end
129
- end
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
- 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
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
- CouchRest::Model::Config.edit do
146
- database Blog do
147
- default "http://localhost:5984/blog"
148
- end
149
- end
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: 29
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
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