rid 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. data/.gitignore +21 -0
  2. data/.gitmodules +3 -0
  3. data/LICENSE +20 -0
  4. data/README.rdoc +93 -0
  5. data/Rakefile +72 -0
  6. data/bin/rid +7 -0
  7. data/lib/rid.rb +43 -0
  8. data/lib/rid/actions/base.rb +15 -0
  9. data/lib/rid/actions/pull.rb +28 -0
  10. data/lib/rid/actions/push.rb +53 -0
  11. data/lib/rid/actions/routes.rb +41 -0
  12. data/lib/rid/attachments.rb +59 -0
  13. data/lib/rid/commands.rb +41 -0
  14. data/lib/rid/commands/destroy.rb +9 -0
  15. data/lib/rid/commands/generate.rb +9 -0
  16. data/lib/rid/commands/pull.rb +4 -0
  17. data/lib/rid/commands/push.rb +4 -0
  18. data/lib/rid/commands/routes.rb +4 -0
  19. data/lib/rid/design_document.rb +179 -0
  20. data/lib/rid/generators.rb +63 -0
  21. data/lib/rid/generators/application/USAGE +10 -0
  22. data/lib/rid/generators/application/application_generator.rb +51 -0
  23. data/lib/rid/generators/application/templates/README +1 -0
  24. data/lib/rid/generators/application/templates/_attachments/index.html +11 -0
  25. data/lib/rid/generators/application/templates/_attachments/stylesheets/application.css +25 -0
  26. data/lib/rid/generators/application/templates/_id +1 -0
  27. data/lib/rid/generators/application/templates/gitignore +0 -0
  28. data/lib/rid/generators/application/templates/lib/mustache.js +305 -0
  29. data/lib/rid/generators/application/templates/ridrc +1 -0
  30. data/lib/rid/generators/application/templates/validate_doc_update.js +3 -0
  31. data/lib/rid/generators/base.rb +66 -0
  32. data/lib/rid/generators/list/USAGE +8 -0
  33. data/lib/rid/generators/list/list_generator.rb +9 -0
  34. data/lib/rid/generators/list/templates/list.js +29 -0
  35. data/lib/rid/generators/named_base.rb +22 -0
  36. data/lib/rid/generators/scaffold/USAGE +10 -0
  37. data/lib/rid/generators/scaffold/scaffold_generator.rb +28 -0
  38. data/lib/rid/generators/show/USAGE +8 -0
  39. data/lib/rid/generators/show/show_generator.rb +9 -0
  40. data/lib/rid/generators/show/templates/show.js +20 -0
  41. data/lib/rid/generators/validation/USAGE +9 -0
  42. data/lib/rid/generators/validation/templates/validate_doc_update.js +3 -0
  43. data/lib/rid/generators/validation/validation_generator.rb +34 -0
  44. data/lib/rid/generators/view/USAGE +8 -0
  45. data/lib/rid/generators/view/templates/map.js +5 -0
  46. data/lib/rid/generators/view/view_generator.rb +17 -0
  47. data/lib/rid/makros.rb +105 -0
  48. data/lib/rid/version.rb +3 -0
  49. data/rid.gemspec +113 -0
  50. data/spec/rid/design_document_spec.rb +329 -0
  51. data/spec/rid_spec.rb +7 -0
  52. data/spec/spec.opts +1 -0
  53. data/spec/spec_helper.rb +9 -0
  54. metadata +187 -0
@@ -0,0 +1,329 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+ require 'rid/design_document'
3
+
4
+ describe "DesignDocument" do
5
+ before do
6
+ @doc = Rid::DesignDocument.new
7
+ end
8
+
9
+ describe "read" do
10
+ it "should assign key-value pair" do
11
+ @doc.read("key") do |filename|
12
+ "value"
13
+ end
14
+ @doc.hash.should == { "key" => "value" }
15
+ end
16
+
17
+ it "should assign two key-value pairs" do
18
+ @doc.read("key1", "key2") do |filename|
19
+ "value"
20
+ end
21
+ @doc.hash.should == { "key1" => "value", "key2" => "value" }
22
+ end
23
+
24
+ it "should assign an array of two key-value pairs" do
25
+ @doc.read(["key1", "key2"]) do |filename|
26
+ "value"
27
+ end
28
+ @doc.hash.should == { "key1" => "value", "key2" => "value" }
29
+ end
30
+
31
+ it "should assign nested hash" do
32
+ @doc.read("hash/key") do |filename|
33
+ "value"
34
+ end
35
+ @doc.hash.should == { "hash" => { "key" => "value" } }
36
+ end
37
+
38
+ it "should assign deep nested hash" do
39
+ @doc.read("hash/hash/key") do |filename|
40
+ "value"
41
+ end
42
+ @doc.hash.should == { "hash" => { "hash" => { "key" => "value" } } }
43
+ end
44
+
45
+ describe "_attachments encoding and content_type" do
46
+ it "should proper encode and add plain text content type" do
47
+ @doc.read("_attachments/key") do |filename|
48
+ "value"
49
+ end
50
+ @doc.hash.should == { "_attachments" => { "key" => { "data" => "dmFsdWU=", "content_type" => "text/plain" } } }
51
+ end
52
+
53
+ it "should proper encode and add html content type" do
54
+ @doc.read("_attachments/key.html") do |filename|
55
+ "value"
56
+ end
57
+ @doc.hash.should == { "_attachments" => { "key.html" => { "data" => "dmFsdWU=", "content_type" => "text/html" } } }
58
+ end
59
+
60
+ it "should proper encode nested keys" do
61
+ @doc.read("_attachments/hash/key") do |filename|
62
+ "value"
63
+ end
64
+ @doc.hash.should == { "_attachments" => { "hash/key" => { "data" => "dmFsdWU=", "content_type" => "text/plain" } } }
65
+ end
66
+ end
67
+
68
+ describe "exclude files should not be mapped" do
69
+ it "should not map README" do
70
+ @doc.read("README") do |filename|
71
+ "value"
72
+ end
73
+ @doc.hash.should == {}
74
+ end
75
+ end
76
+
77
+ describe "javascript files should be stripped off extension" do
78
+ it "should strip validate_doc_update extension" do
79
+ @doc.read("validate_doc_update.js") do |filename|
80
+ "value"
81
+ end
82
+ @doc.hash.should == { "validate_doc_update" => "value" }
83
+ end
84
+
85
+ it "should strip lists/my_list.js" do
86
+ @doc.read("lists/my_list.js") do |filename|
87
+ "value"
88
+ end
89
+ @doc.hash.should == { "lists" => { "my_list" => "value" } }
90
+ end
91
+
92
+ it "should strip views/my_view/map.js" do
93
+ @doc.read("views/my_view/map.js") do |filename|
94
+ "value"
95
+ end
96
+ @doc.hash.should == { "views" => { "my_view" => { "map" => "value" } } }
97
+ end
98
+ end
99
+
100
+ describe "code makro" do
101
+ it "should expand code" do
102
+ idx = 0
103
+ @doc.read("key", "lib/code.js") do |filename|
104
+ case idx += 1
105
+ when 1
106
+ "// !code code.js"
107
+ when 2
108
+ "value"
109
+ end
110
+ end
111
+ @doc.hash.should == { "key" => "value", "lib" => { "code.js" => "value" } }
112
+ end
113
+ end
114
+
115
+ describe "json makro" do
116
+ it "should expand json" do
117
+ idx = 0
118
+ @doc.read("key", "lib/json.json") do |filename|
119
+ case idx += 1
120
+ when 1
121
+ "// !json json.json"
122
+ when 2
123
+ "value"
124
+ end
125
+ end
126
+ @doc.hash.should == { "key" => "var json = \"value\";", "lib" => { "json.json" => "value" } }
127
+ end
128
+ end
129
+ end
130
+
131
+ describe "write" do
132
+ it "should return key-value pair" do
133
+ @doc.hash = { "key" => "value" }
134
+ filename, content = nil, nil
135
+ @doc.write do |key, value|
136
+ filename, content = key, value
137
+ end
138
+ filename.should == "key"
139
+ content.should == "value"
140
+ end
141
+
142
+ it "should return subdirectory for nested hash" do
143
+ @doc.hash = { "hash" => { "key" => "value" } }
144
+ filename, content = nil, nil
145
+ @doc.write do |key, value|
146
+ filename, content = key, value
147
+ end
148
+ filename.should == "hash/key"
149
+ content.should == "value"
150
+ end
151
+
152
+ it "should return subdirectory for nested hash" do
153
+ @doc.hash = { "hash" => { "hash" => { "key" => "value" } } }
154
+ filename, content = nil, nil
155
+ @doc.write do |key, value|
156
+ filename, content = key, value
157
+ end
158
+ filename.should == "hash/hash/key"
159
+ content.should == "value"
160
+ end
161
+
162
+ it "should return decoded _attachments data" do
163
+ @doc.hash = { "_attachments" => { "key" => { "data" => "dmFsdWU=" } } }
164
+ filename, content = nil, nil
165
+ @doc.write do |key, value|
166
+ filename, content = key, value
167
+ end
168
+ filename.should == "_attachments/key"
169
+ content.should == "value"
170
+ end
171
+
172
+ describe "javascript extensions" do
173
+ it "should append validate_doc_update" do
174
+ @doc.hash = { "validate_doc_update" => "value" }
175
+ filename = nil
176
+ @doc.write do |key, value|
177
+ filename = key
178
+ end
179
+ filename.should == "validate_doc_update.js"
180
+ end
181
+
182
+ it "should append lists/my_list" do
183
+ @doc.hash = { "lists" => { "my_list" => "value" } }
184
+ filename = nil
185
+ @doc.write do |key, value|
186
+ filename = key
187
+ end
188
+ filename.should == "lists/my_list.js"
189
+ end
190
+
191
+ it "should append views/my_view/map" do
192
+ @doc.hash = { "views" => { "my_view" => { "map" => "value" } } }
193
+ filename = nil
194
+ @doc.write do |key, value|
195
+ filename = key
196
+ end
197
+ filename.should == "views/my_view/map.js"
198
+ end
199
+ end
200
+
201
+ describe "code makro" do
202
+ it "should reject code" do
203
+ @doc.hash = { "key" => "value", "lib" => { "code.js" => "value" } }
204
+ content = nil
205
+ @doc.write do |key, value|
206
+ content = value
207
+ end
208
+ content.should == "// !code code.js"
209
+ end
210
+
211
+ it "should reject nested code" do
212
+ @doc.hash = { "key" => "value", "lib" => { "hash" => { "code.js" => "value" } } }
213
+ content = nil
214
+ @doc.write do |key, value|
215
+ content = value
216
+ end
217
+ content.should == "// !code hash/code.js"
218
+ end
219
+ end
220
+
221
+ describe "json makro" do
222
+ it "should reject json" do
223
+ @doc.hash = { "key" => "var json = \"value\";", "lib" => { "json.json" => "value" } }
224
+ content = nil
225
+ @doc.write do |key, value|
226
+ content = value
227
+ end
228
+ content.should == "// !json json.json"
229
+ end
230
+
231
+ it "should reject nested json" do
232
+ @doc.hash = { "key" => "var json = \"value\";", "lib" => { "hash" => { "json.json" => "value" } } }
233
+ content = nil
234
+ @doc.write do |key, value|
235
+ content = value
236
+ end
237
+ content.should == "// !json hash/json.json"
238
+ end
239
+ end
240
+ end
241
+
242
+ describe "json" do
243
+ it "should convert key-value pair" do
244
+ @doc.hash = { "key" => "value" }
245
+ @doc.json.should == '{"key":"value"}'
246
+ end
247
+
248
+ it "should convert nested hash" do
249
+ @doc.hash = { "hash" => { "key" => "value" } }
250
+ @doc.json.should == '{"hash":{"key":"value"}}'
251
+ end
252
+ end
253
+
254
+ describe "json=" do
255
+ it "should read key-value pair" do
256
+ @doc.json = '{"key":"value"}'
257
+ @doc.hash.should == { "key" => "value" }
258
+ end
259
+
260
+ it "should read nested hash" do
261
+ @doc.json = '{"hash":{"key":"value"}}'
262
+ @doc.hash.should == { "hash" => { "key" => "value" } }
263
+ end
264
+ end
265
+
266
+ describe "id accessor" do
267
+ it "should return id from hash" do
268
+ @doc.hash = { "_id" => "my_id" }
269
+ @doc.id.should == "my_id"
270
+ end
271
+
272
+ it "should return id from rid" do
273
+ Rid.stub!(:id).and_return("my_id")
274
+ @doc.hash = {}
275
+ @doc.id.should == "my_id"
276
+ end
277
+ end
278
+
279
+ describe "rev accessor" do
280
+ it "should return rev from hash" do
281
+ @doc.hash = { "_rev" => "my_rev" }
282
+ @doc.rev.should == "my_rev"
283
+ end
284
+
285
+ it "should return rev from rid" do
286
+ Rid.stub!(:rev).and_return("my_rev")
287
+ @doc.hash = {}
288
+ @doc.rev.should == "my_rev"
289
+ end
290
+
291
+ it "should update rev in hash" do
292
+ @doc.hash = {}
293
+ @doc.rev = "my_rev"
294
+ @doc.hash.should == { "_rev" => "my_rev" }
295
+ end
296
+ end
297
+
298
+ describe "database accessor" do
299
+ it "should return database rid" do
300
+ Rid.stub!(:database).and_return("my_db")
301
+ @doc.database.should == "my_db"
302
+ end
303
+ end
304
+
305
+ describe "base url" do
306
+ it "should combine database and id" do
307
+ @doc.should_receive(:id).and_return("my_id")
308
+ @doc.should_receive(:database).and_return("my_db")
309
+ @doc.base_url.should == "my_db/my_id"
310
+ end
311
+ end
312
+
313
+ describe "url" do
314
+ it "should return base_url without options" do
315
+ @doc.should_receive(:base_url).and_return("my_base_url")
316
+ @doc.url.should == "my_base_url"
317
+ end
318
+
319
+ it "should return base_url with options string" do
320
+ @doc.should_receive(:base_url).and_return("my_base_url")
321
+ @doc.url(:key => :value).should == "my_base_url?key=value"
322
+ end
323
+
324
+ it "should return base_url with properly escaped options string" do
325
+ @doc.should_receive(:base_url).and_return("my_base_url")
326
+ @doc.url(:key => "value value").should == "my_base_url?key=value%20value"
327
+ end
328
+ end
329
+ end
@@ -0,0 +1,7 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Rid" do
4
+ it "should return .ridrc as config filename" do
5
+ Rid::CONFIG_FILENAME.should == '.ridrc'
6
+ end
7
+ end
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,9 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'rid'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+
7
+ Spec::Runner.configure do |config|
8
+
9
+ end
metadata ADDED
@@ -0,0 +1,187 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rid
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 3
8
+ - 0
9
+ version: 0.3.0
10
+ platform: ruby
11
+ authors:
12
+ - Johannes J. Schmidt
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-03-11 00:00:00 +01:00
18
+ default_executable: rid
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: thor
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ - 13
30
+ - 4
31
+ version: 0.13.4
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: rest-client
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 1
43
+ - 4
44
+ - 1
45
+ version: 1.4.1
46
+ type: :runtime
47
+ version_requirements: *id002
48
+ - !ruby/object:Gem::Dependency
49
+ name: json_pure
50
+ prerelease: false
51
+ requirement: &id003 !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ segments:
56
+ - 1
57
+ - 2
58
+ - 2
59
+ version: 1.2.2
60
+ type: :runtime
61
+ version_requirements: *id003
62
+ - !ruby/object:Gem::Dependency
63
+ name: activesupport
64
+ prerelease: false
65
+ requirement: &id004 !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ segments:
70
+ - 3
71
+ - 0
72
+ - 0
73
+ - beta
74
+ version: 3.0.0.beta
75
+ type: :runtime
76
+ version_requirements: *id004
77
+ - !ruby/object:Gem::Dependency
78
+ name: rspec
79
+ prerelease: false
80
+ requirement: &id005 !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ segments:
85
+ - 1
86
+ - 2
87
+ - 9
88
+ version: 1.2.9
89
+ type: :development
90
+ version_requirements: *id005
91
+ description: With Couch you can easy build a standalone CouchDB application. Couch aims to bring some of the Rails beauty to CouchDB. Currently Couch supports Rails style Generators you will love, using the same awesome Thor library used in Rails3.
92
+ email: schmidt@netzmerk.com
93
+ executables:
94
+ - rid
95
+ extensions: []
96
+
97
+ extra_rdoc_files:
98
+ - LICENSE
99
+ - README.rdoc
100
+ files:
101
+ - .gitignore
102
+ - .gitmodules
103
+ - LICENSE
104
+ - README.rdoc
105
+ - Rakefile
106
+ - bin/rid
107
+ - lib/rid.rb
108
+ - lib/rid/actions/base.rb
109
+ - lib/rid/actions/pull.rb
110
+ - lib/rid/actions/push.rb
111
+ - lib/rid/actions/routes.rb
112
+ - lib/rid/attachments.rb
113
+ - lib/rid/commands.rb
114
+ - lib/rid/commands/destroy.rb
115
+ - lib/rid/commands/generate.rb
116
+ - lib/rid/commands/pull.rb
117
+ - lib/rid/commands/push.rb
118
+ - lib/rid/commands/routes.rb
119
+ - lib/rid/design_document.rb
120
+ - lib/rid/generators.rb
121
+ - lib/rid/generators/application/USAGE
122
+ - lib/rid/generators/application/application_generator.rb
123
+ - lib/rid/generators/application/templates/README
124
+ - lib/rid/generators/application/templates/_attachments/index.html
125
+ - lib/rid/generators/application/templates/_attachments/stylesheets/application.css
126
+ - lib/rid/generators/application/templates/_id
127
+ - lib/rid/generators/application/templates/gitignore
128
+ - lib/rid/generators/application/templates/lib/mustache.js
129
+ - lib/rid/generators/application/templates/ridrc
130
+ - lib/rid/generators/application/templates/validate_doc_update.js
131
+ - lib/rid/generators/base.rb
132
+ - lib/rid/generators/list/USAGE
133
+ - lib/rid/generators/list/list_generator.rb
134
+ - lib/rid/generators/list/templates/list.js
135
+ - lib/rid/generators/named_base.rb
136
+ - lib/rid/generators/scaffold/USAGE
137
+ - lib/rid/generators/scaffold/scaffold_generator.rb
138
+ - lib/rid/generators/show/USAGE
139
+ - lib/rid/generators/show/show_generator.rb
140
+ - lib/rid/generators/show/templates/show.js
141
+ - lib/rid/generators/validation/USAGE
142
+ - lib/rid/generators/validation/templates/validate_doc_update.js
143
+ - lib/rid/generators/validation/validation_generator.rb
144
+ - lib/rid/generators/view/USAGE
145
+ - lib/rid/generators/view/templates/map.js
146
+ - lib/rid/generators/view/view_generator.rb
147
+ - lib/rid/makros.rb
148
+ - lib/rid/version.rb
149
+ - rid.gemspec
150
+ - spec/rid/design_document_spec.rb
151
+ - spec/rid_spec.rb
152
+ - spec/spec.opts
153
+ - spec/spec_helper.rb
154
+ has_rdoc: true
155
+ homepage: http://github.com/jo/rid
156
+ licenses: []
157
+
158
+ post_install_message:
159
+ rdoc_options:
160
+ - --charset=UTF-8
161
+ require_paths:
162
+ - lib
163
+ required_ruby_version: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - ">="
166
+ - !ruby/object:Gem::Version
167
+ segments:
168
+ - 0
169
+ version: "0"
170
+ required_rubygems_version: !ruby/object:Gem::Requirement
171
+ requirements:
172
+ - - ">="
173
+ - !ruby/object:Gem::Version
174
+ segments:
175
+ - 0
176
+ version: "0"
177
+ requirements: []
178
+
179
+ rubyforge_project: rid
180
+ rubygems_version: 1.3.6
181
+ signing_key:
182
+ specification_version: 3
183
+ summary: Standalone Couchdb Application Development Suite
184
+ test_files:
185
+ - spec/spec_helper.rb
186
+ - spec/rid_spec.rb
187
+ - spec/rid/design_document_spec.rb