rufus-doric 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.txt +8 -0
- data/LICENSE.txt +21 -0
- data/README.rdoc +42 -0
- data/Rakefile +78 -0
- data/TODO.txt +9 -0
- data/lib/rufus/doric/couch.rb +84 -0
- data/lib/rufus/doric/fixtures.rb +217 -0
- data/lib/rufus/doric/model.rb +300 -0
- data/lib/rufus/doric/models.rb +122 -0
- data/lib/rufus/doric/one_doc_model.rb +136 -0
- data/lib/rufus/doric/version.rb +7 -0
- data/lib/rufus/doric.rb +4 -0
- data/lib/rufus-doric.rb +3 -0
- data/rufus-doric.gemspec +90 -0
- data/test/base.rb +16 -0
- data/test/fixtures/test/doric/69247b__picture.jpg +0 -0
- data/test/fixtures/test/doric/69249__picture.jpg +0 -0
- data/test/fixtures/test/doric/product0.json +8 -0
- data/test/fixtures/test/doric/product1.json +8 -0
- data/test/fixtures/test/doric/users.json +18 -0
- data/test/fixtures/test/doric/users__jami.png +0 -0
- data/test/fixtures/test/doric/users__john.jpg +0 -0
- data/test/fixtures/test/doric_ENV_workitems/workitem0.json +17 -0
- data/test/test.rb +3 -0
- data/test/ut_0_fixtures.rb +63 -0
- data/test/ut_1_model.rb +133 -0
- data/test/ut_2_model_view.rb +59 -0
- data/test/ut_3_model_lint.rb +27 -0
- data/test/ut_4_one_doc_model.rb +86 -0
- metadata +169 -0
data/CHANGELOG.txt
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
|
2
|
+
Copyright (c) 2010, John Mettraux, jmettraux@gmail.com
|
3
|
+
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
|
+
of this software and associated documentation files (the "Software"), to deal
|
6
|
+
in the Software without restriction, including without limitation the rights
|
7
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
copies of the Software, and to permit persons to whom the Software is
|
9
|
+
furnished to do so, subject to the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be included in
|
12
|
+
all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
17
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
19
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
20
|
+
THE SOFTWARE.
|
21
|
+
|
data/README.rdoc
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
|
2
|
+
= rufus-doric
|
3
|
+
|
4
|
+
something at the intersection of Rails3, CouchDB and rufus-jig.
|
5
|
+
|
6
|
+
|
7
|
+
== Rufus::Doric::Model usage
|
8
|
+
|
9
|
+
see tests
|
10
|
+
|
11
|
+
== Rufus::Doric::OneDocModel usage
|
12
|
+
|
13
|
+
see tests
|
14
|
+
|
15
|
+
|
16
|
+
== 'fixtures' usage
|
17
|
+
|
18
|
+
Given a fixture tree
|
19
|
+
|
20
|
+
fixtures
|
21
|
+
`-- test
|
22
|
+
`-- doric
|
23
|
+
|-- 69247b__picture.jpg
|
24
|
+
|-- 69249__picture.jpg
|
25
|
+
|-- product0.json
|
26
|
+
|-- product1.json
|
27
|
+
|-- users.json
|
28
|
+
|-- users__jami.png
|
29
|
+
`-- users__john.jpg
|
30
|
+
|
31
|
+
this
|
32
|
+
|
33
|
+
require 'rufus/doric/fixtures'
|
34
|
+
Rufus::Doric::Fixtures.load('http://127.0.0.1:5984', 'fixtures/test')
|
35
|
+
|
36
|
+
will load the documents (and their attachements) into http://127.0.0.1:5984/doric_test
|
37
|
+
|
38
|
+
|
39
|
+
== license
|
40
|
+
|
41
|
+
MIT
|
42
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
require 'lib/rufus/doric/version.rb'
|
4
|
+
|
5
|
+
require 'rubygems'
|
6
|
+
require 'rake'
|
7
|
+
|
8
|
+
|
9
|
+
#
|
10
|
+
# CLEAN
|
11
|
+
|
12
|
+
require 'rake/clean'
|
13
|
+
CLEAN.include('pkg', 'tmp', 'html')
|
14
|
+
task :default => [ :clean ]
|
15
|
+
|
16
|
+
|
17
|
+
#
|
18
|
+
# GEM
|
19
|
+
|
20
|
+
require 'jeweler'
|
21
|
+
|
22
|
+
Jeweler::Tasks.new do |gem|
|
23
|
+
|
24
|
+
gem.version = Rufus::Doric::VERSION
|
25
|
+
gem.name = 'rufus-doric'
|
26
|
+
gem.summary = 'something at the intersection of Rails3, CouchDB and rufus-jig'
|
27
|
+
|
28
|
+
gem.description = %{
|
29
|
+
something at the intersection of Rails3, CouchDB and rufus-jig
|
30
|
+
}
|
31
|
+
gem.email = 'jmettraux@gmail.com'
|
32
|
+
gem.homepage = 'http://github.com/jmettraux/rufus-doric/'
|
33
|
+
gem.authors = [ 'John Mettraux' ]
|
34
|
+
gem.rubyforge_project = 'rufus'
|
35
|
+
|
36
|
+
gem.test_file = 'test/test.rb'
|
37
|
+
|
38
|
+
gem.add_dependency 'activerecord', '~> 3.0.0.beta'
|
39
|
+
gem.add_dependency 'rufus-jig', '>= 0.1.16'
|
40
|
+
gem.add_dependency 'mime-types', '>= 1.16'
|
41
|
+
gem.add_development_dependency 'rake'
|
42
|
+
gem.add_development_dependency 'yard'
|
43
|
+
gem.add_development_dependency 'jeweler'
|
44
|
+
|
45
|
+
# gemspec spec : http://www.rubygems.org/read/chapter/20
|
46
|
+
end
|
47
|
+
Jeweler::GemcutterTasks.new
|
48
|
+
|
49
|
+
|
50
|
+
#
|
51
|
+
# DOC
|
52
|
+
|
53
|
+
begin
|
54
|
+
require 'yard'
|
55
|
+
YARD::Rake::YardocTask.new do |doc|
|
56
|
+
doc.options = [
|
57
|
+
'-o', 'html/rufus-doric', '--title',
|
58
|
+
"rufus-doric #{Rufus::Doric::VERSION}"
|
59
|
+
]
|
60
|
+
end
|
61
|
+
rescue LoadError
|
62
|
+
task :yard do
|
63
|
+
abort "YARD is not available : sudo gem install yard"
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
|
68
|
+
#
|
69
|
+
# TO THE WEB
|
70
|
+
|
71
|
+
task :upload_website => [ :clean, :yard ] do
|
72
|
+
|
73
|
+
account = 'jmettraux@rubyforge.org'
|
74
|
+
webdir = '/var/www/gforge-projects/rufus'
|
75
|
+
|
76
|
+
sh "rsync -azv -e ssh html/rufus-doric #{account}:#{webdir}/"
|
77
|
+
end
|
78
|
+
|
data/TODO.txt
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2010, John Mettraux, jmettraux@gmail.com
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
|
+
# of this software and associated documentation files (the "Software"), to deal
|
6
|
+
# in the Software without restriction, including without limitation the rights
|
7
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
# copies of the Software, and to permit persons to whom the Software is
|
9
|
+
# furnished to do so, subject to the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be included in
|
12
|
+
# all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
17
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
19
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
20
|
+
# THE SOFTWARE.
|
21
|
+
#
|
22
|
+
# Made in Japan.
|
23
|
+
#++
|
24
|
+
|
25
|
+
#require 'rufus/doric/models'
|
26
|
+
#require 'rufus/doric/fixtures'
|
27
|
+
|
28
|
+
|
29
|
+
module Rufus
|
30
|
+
module Doric
|
31
|
+
|
32
|
+
module Couch
|
33
|
+
|
34
|
+
def self.url
|
35
|
+
|
36
|
+
if defined?(Rails)
|
37
|
+
return File.read(Rails.root.join('config', 'couch_url.txt')).strip
|
38
|
+
end
|
39
|
+
if File.exist?('couch_url.txt')
|
40
|
+
return File.read('couch_url.txt').strip
|
41
|
+
end
|
42
|
+
|
43
|
+
'http://127.0.0.1:5984'
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.couch
|
47
|
+
|
48
|
+
Rufus::Jig::Couch.new(url)
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.db (name, opts={})
|
52
|
+
|
53
|
+
env = opts[:env]
|
54
|
+
env ||= Rails.env if defined?(Rails)
|
55
|
+
env ||= 'test'
|
56
|
+
|
57
|
+
u = opts[:absolute] ? "#{url}/#{name}" : "#{url}/#{name}_#{env}"
|
58
|
+
|
59
|
+
return u if opts[:url_only] || opts[:uo]
|
60
|
+
|
61
|
+
Rufus::Jig::Couch.new(u)
|
62
|
+
end
|
63
|
+
|
64
|
+
# def self.purge! TODO (name, env)
|
65
|
+
#
|
66
|
+
# result = Doric::Couch.get('_all_docs')
|
67
|
+
#
|
68
|
+
# return unless result
|
69
|
+
#
|
70
|
+
# result['rows'].each do |r|
|
71
|
+
#
|
72
|
+
# _id = r['id']
|
73
|
+
#
|
74
|
+
# next if _id.match(/^\_design\//)
|
75
|
+
#
|
76
|
+
# _rev = r['value']['rev']
|
77
|
+
#
|
78
|
+
# Doric::Couch.delete('_id' => _id, '_rev' => _rev)
|
79
|
+
# end
|
80
|
+
# end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
@@ -0,0 +1,217 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2010, John Mettraux, jmettraux@gmail.com
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
|
+
# of this software and associated documentation files (the "Software"), to deal
|
6
|
+
# in the Software without restriction, including without limitation the rights
|
7
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
# copies of the Software, and to permit persons to whom the Software is
|
9
|
+
# furnished to do so, subject to the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be included in
|
12
|
+
# all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
17
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
19
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
20
|
+
# THE SOFTWARE.
|
21
|
+
#
|
22
|
+
# Made in Japan.
|
23
|
+
#++
|
24
|
+
|
25
|
+
require 'mime/types'
|
26
|
+
require 'rufus-jig'
|
27
|
+
|
28
|
+
|
29
|
+
module Rufus
|
30
|
+
module Doric
|
31
|
+
|
32
|
+
module Fixtures
|
33
|
+
|
34
|
+
ATT_TYPES = %w[ .png .gif .jpg .jpeg .pdf ]
|
35
|
+
|
36
|
+
# Given a fixture tree
|
37
|
+
#
|
38
|
+
# test/
|
39
|
+
# `-- fixtures
|
40
|
+
# `-- test
|
41
|
+
# `-- doric
|
42
|
+
# |-- 69247b__picture.jpg
|
43
|
+
# |-- 69249__picture.jpg
|
44
|
+
# |-- product0.json
|
45
|
+
# |-- product1.json
|
46
|
+
# |-- users.json
|
47
|
+
# |-- users__jami.png
|
48
|
+
# `-- users__john.jpg
|
49
|
+
#
|
50
|
+
# this
|
51
|
+
#
|
52
|
+
# require 'rufus/doric/fixtures'
|
53
|
+
# Rufus::Doric::Fixtures.load('http://127.0.0.1:5984', 'fixtures/test')
|
54
|
+
#
|
55
|
+
# will load the documents (and their attachements)
|
56
|
+
# into http://127.0.0.1:5984/doric_test
|
57
|
+
#
|
58
|
+
#
|
59
|
+
# == options
|
60
|
+
#
|
61
|
+
# === :env
|
62
|
+
#
|
63
|
+
# by default env is set to the name of the fixture root dir ('test'
|
64
|
+
# in our example above)
|
65
|
+
#
|
66
|
+
# === :create
|
67
|
+
#
|
68
|
+
# when true and the db doesn't exist, will create it
|
69
|
+
#
|
70
|
+
# === :purge
|
71
|
+
#
|
72
|
+
# when true will delete all docs before inserting, implies :create => true
|
73
|
+
#
|
74
|
+
# === :overwrite
|
75
|
+
#
|
76
|
+
# when true, if a doc is already present, will overwrite it
|
77
|
+
#
|
78
|
+
# === :db
|
79
|
+
#
|
80
|
+
# takes a String. Sets the name of the Couch database absolutely
|
81
|
+
#
|
82
|
+
# === :verbose
|
83
|
+
#
|
84
|
+
# when true, turns verbose. Here is an example output :
|
85
|
+
#
|
86
|
+
# .couch is at http://127.0.0.1:5984
|
87
|
+
# .fixtures are at test/fixtures/test
|
88
|
+
# .env is 'test'
|
89
|
+
# .opts are {:create=>true, :purge=>true, :verbose=>true}
|
90
|
+
# .purged db at http://127.0.0.1:5984/doric_test
|
91
|
+
# .loading into http://127.0.0.1:5984/doric_test
|
92
|
+
# .reading test/fixtures/test/doric/product0.json
|
93
|
+
# .inserting at http://127.0.0.1:5984/doric_test/69249
|
94
|
+
# .reading test/fixtures/test/doric/product1.json
|
95
|
+
# .inserting at http://127.0.0.1:5984/doric_test/69247b
|
96
|
+
# .reading test/fixtures/test/doric/users.json
|
97
|
+
# .inserting at http://127.0.0.1:5984/doric_test/users
|
98
|
+
# .loading attachments into http://127.0.0.1:5984/doric_test
|
99
|
+
# .reading test/fixtures/test/doric/69247b__picture.jpg
|
100
|
+
# .inserting at http://127.0.0.1:5984/doric_test/69247b/picture.jpg
|
101
|
+
# .reading test/fixtures/test/doric/69249__picture.jpg
|
102
|
+
# .inserting at http://127.0.0.1:5984/doric_test/69249/picture.jpg
|
103
|
+
# .reading test/fixtures/test/doric/users__jami.png
|
104
|
+
# .inserting at http://127.0.0.1:5984/doric_test/users/jami.png
|
105
|
+
# .reading test/fixtures/test/doric/users__john.jpg
|
106
|
+
# .inserting at http://127.0.0.1:5984/doric_test/users/john.jpg
|
107
|
+
#
|
108
|
+
def self.load (couch_uri, path, opts={})
|
109
|
+
|
110
|
+
env = opts[:env] || File.split(path).last
|
111
|
+
verbose = opts[:verbose]
|
112
|
+
|
113
|
+
if verbose
|
114
|
+
puts ".couch is at #{couch_uri}"
|
115
|
+
puts ".fixtures are at #{path}"
|
116
|
+
puts ".env is '#{env}'"
|
117
|
+
puts ".opts are #{opts.inspect}"
|
118
|
+
end
|
119
|
+
|
120
|
+
Dir[File.join(path, '*')].each do |dbpath|
|
121
|
+
|
122
|
+
dbname = File.split(dbpath).last
|
123
|
+
|
124
|
+
db_uri = dbname.index('_ENV_') ?
|
125
|
+
"#{couch_uri}/#{dbname.gsub(/\_ENV\_/, "_#{env}_")}" :
|
126
|
+
"#{couch_uri}/#{dbname}_#{env}"
|
127
|
+
|
128
|
+
if dbname.index('_ENV_').nil? && dbn = opts[:db]
|
129
|
+
db_uri = "#{couch_uri}/#{dbn}"
|
130
|
+
end
|
131
|
+
|
132
|
+
db = Rufus::Jig::Couch.new(db_uri)
|
133
|
+
|
134
|
+
if db.get('.').nil?
|
135
|
+
if opts[:create] || opts[:purge]
|
136
|
+
db.put('.')
|
137
|
+
puts " .created db at #{db_uri}" if verbose
|
138
|
+
else
|
139
|
+
raise(ArgumentError.new("db #{db_uri} doesn't exist"))
|
140
|
+
end
|
141
|
+
else
|
142
|
+
if opts[:purge]
|
143
|
+
db.delete('.')
|
144
|
+
db.put('.')
|
145
|
+
puts " .purged db at #{db_uri}" if verbose
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
puts " .loading into #{db_uri}" if verbose
|
150
|
+
|
151
|
+
#
|
152
|
+
# load documents
|
153
|
+
|
154
|
+
Dir[File.join(dbpath, '*.json')].each do |docpath|
|
155
|
+
|
156
|
+
puts " .reading ...#{docpath[-60..-1]}" if verbose
|
157
|
+
|
158
|
+
doc = Rufus::Json.decode(File.read(docpath))
|
159
|
+
|
160
|
+
current_doc = db.get(doc['_id'])
|
161
|
+
|
162
|
+
if current_doc && (not opts[:overwrite])
|
163
|
+
puts " .skipping #{doc['_id']} (:overwrite == false)"
|
164
|
+
next
|
165
|
+
end
|
166
|
+
|
167
|
+
db.delete(current_doc) if current_doc
|
168
|
+
|
169
|
+
puts " .inserting at #{db_uri}/#{doc['_id']}" if verbose
|
170
|
+
db.put(doc)
|
171
|
+
end
|
172
|
+
|
173
|
+
#
|
174
|
+
# load attachments
|
175
|
+
|
176
|
+
puts " .loading attachments into #{db_uri}" if verbose
|
177
|
+
|
178
|
+
Dir[File.join(dbpath, '*')].each do |attpath|
|
179
|
+
|
180
|
+
next if attpath.match(/\.json$/)
|
181
|
+
|
182
|
+
ext = File.extname(attpath).downcase
|
183
|
+
|
184
|
+
next unless ATT_TYPES.include?(ext)
|
185
|
+
|
186
|
+
docid, attname = File.basename(attpath).split('__')
|
187
|
+
|
188
|
+
puts " .reading ...#{attpath[-60..-1]}" if verbose
|
189
|
+
|
190
|
+
current_att = db.get(File.join(docid, attname))
|
191
|
+
|
192
|
+
if current_att && (not opts[:overwrite])
|
193
|
+
puts " .skipping #{docid}/#{attname} (:overwrite == false)"
|
194
|
+
next
|
195
|
+
end
|
196
|
+
|
197
|
+
doc = db.get(docid)
|
198
|
+
|
199
|
+
raise(
|
200
|
+
ArgumentError.new("cannot attach to missing document #{docid}")
|
201
|
+
) unless doc
|
202
|
+
|
203
|
+
data = File.read(attpath)
|
204
|
+
|
205
|
+
puts " .inserting at #{db_uri}/#{docid}/#{attname}" if verbose
|
206
|
+
|
207
|
+
db.attach(
|
208
|
+
doc, attname, data,
|
209
|
+
:content_type => MIME::Types.type_for(attname).first.to_s)
|
210
|
+
end
|
211
|
+
end
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|