ruote-couch 2.1.4 → 2.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.txt +9 -4
- data/Rakefile +1 -1
- data/lib/ruote/couch/database.rb +132 -21
- data/lib/ruote/couch/storage.rb +22 -19
- data/lib/ruote/couch/version.rb +1 -1
- data/ruote-couch.gemspec +8 -8
- data/test/unit/ut_0_initial.rb +2 -4
- metadata +4 -4
data/CHANGELOG.txt
CHANGED
@@ -2,11 +2,16 @@
|
|
2
2
|
= ruote-couch - CHANGELOG.txt
|
3
3
|
|
4
4
|
|
5
|
-
== ruote-couch 2.1.
|
5
|
+
== ruote-couch 2.1.5 released 2010/01/28
|
6
6
|
|
7
|
-
-
|
8
|
-
- Ruote::Couch::Storage added #purge_type!(t)
|
7
|
+
- implemented CouchStorage#by_wfid and #by_participant
|
9
8
|
|
10
9
|
|
11
|
-
== ruote-couch 2.1.
|
10
|
+
== ruote-couch 2.1.4 released 2010/01/11
|
11
|
+
|
12
|
+
- Ruote::Couch::CouchStorage added #ids(type)
|
13
|
+
- Ruote::Couch::CouchStorage added #purge_type!(t)
|
14
|
+
|
15
|
+
|
16
|
+
== ruote-couch 2.1.3 released 2010/01/05
|
12
17
|
|
data/Rakefile
CHANGED
@@ -35,7 +35,7 @@ CouchDB storage for ruote 2.1 (ruby workflow engine)
|
|
35
35
|
gem.add_dependency 'ruote', ">= #{Ruote::Couch::VERSION}"
|
36
36
|
#gem.add_dependency 'yajl-ruby'
|
37
37
|
#gem.add_dependency 'json'
|
38
|
-
gem.add_dependency 'rufus-jig', '>= 0.1.
|
38
|
+
gem.add_dependency 'rufus-jig', '>= 0.1.12'
|
39
39
|
gem.add_development_dependency 'yard', '>= 0'
|
40
40
|
|
41
41
|
# gemspec spec : http://www.rubygems.org/read/chapter/20
|
data/lib/ruote/couch/database.rb
CHANGED
@@ -22,9 +22,14 @@
|
|
22
22
|
# Made in Japan.
|
23
23
|
#++
|
24
24
|
|
25
|
+
require 'cgi'
|
26
|
+
|
25
27
|
|
26
28
|
module Ruote::Couch
|
27
29
|
|
30
|
+
#
|
31
|
+
# A database corresponds to a Couch database (not a Couch server).
|
32
|
+
#
|
28
33
|
class Database
|
29
34
|
|
30
35
|
attr_reader :type
|
@@ -62,20 +67,14 @@ module Ruote::Couch
|
|
62
67
|
|
63
68
|
def get_many (key, opts)
|
64
69
|
|
65
|
-
|
66
|
-
"&limit=#{l}"
|
67
|
-
else
|
68
|
-
''
|
69
|
-
end
|
70
|
-
|
71
|
-
rs = @couch.get("_all_docs?include_docs=true#{os}")
|
70
|
+
rs = @couch.get("_all_docs?include_docs=true#{query_options(opts)}")
|
72
71
|
|
73
72
|
rs = rs['rows'].collect { |e| e['doc'] }
|
74
73
|
|
75
74
|
rs = rs.select { |doc| doc['_id'].match(key) } if key
|
76
75
|
# naive...
|
77
76
|
|
78
|
-
rs
|
77
|
+
rs.select { |doc| ! doc['_id'].match(/^\_design\//) }
|
79
78
|
end
|
80
79
|
|
81
80
|
# Returns a sorted list of the ids of all the docs in this database.
|
@@ -126,28 +125,140 @@ module Ruote::Couch
|
|
126
125
|
|
127
126
|
# nothing to do for a index-less database
|
128
127
|
end
|
128
|
+
|
129
|
+
# (for now, the only option is :limit)
|
130
|
+
#
|
131
|
+
def query_options (opts)
|
132
|
+
|
133
|
+
if l = opts[:limit]
|
134
|
+
"&limit=#{l}"
|
135
|
+
else
|
136
|
+
''
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
def query (uri)
|
141
|
+
|
142
|
+
rs = @couch.get(uri)
|
143
|
+
|
144
|
+
rs['rows'].collect { |e| e['doc'] }
|
145
|
+
end
|
129
146
|
end
|
130
147
|
|
148
|
+
#
|
149
|
+
# A Couch database with a by_wfid view.
|
150
|
+
#
|
131
151
|
class WfidIndexedDatabase < Database
|
132
152
|
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
153
|
+
def get_many (key, opts)
|
154
|
+
|
155
|
+
if key && m = key.source.match(/!?(.+)\$$/)
|
156
|
+
# let's use the couch view...
|
157
|
+
|
158
|
+
query(
|
159
|
+
"_design/ruote/_view/by_wfid?key=%22#{m[1]}%22" +
|
160
|
+
"&include_docs=true#{query_options(opts)}")
|
161
|
+
|
162
|
+
else
|
163
|
+
# let's use the naive default implementation
|
164
|
+
|
165
|
+
super
|
166
|
+
end
|
167
|
+
end
|
145
168
|
|
146
169
|
protected
|
147
170
|
|
171
|
+
def design_doc
|
172
|
+
|
173
|
+
{
|
174
|
+
'_id' => '_design/ruote',
|
175
|
+
'views' => {
|
176
|
+
'by_wfid' => {
|
177
|
+
'map' =>
|
178
|
+
'function (doc) { if (doc.fei) emit(doc.fei.wfid, null); }'
|
179
|
+
}
|
180
|
+
}
|
181
|
+
}
|
182
|
+
end
|
183
|
+
|
148
184
|
def prepare
|
149
185
|
|
150
|
-
|
186
|
+
d = @couch.get('_design/ruote')
|
187
|
+
@couch.delete(d) if d
|
188
|
+
@couch.put(design_doc)
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
#
|
193
|
+
# A Couch database with a by_wfid view and a by_field view.
|
194
|
+
#
|
195
|
+
class WorkitemDatabase < WfidIndexedDatabase
|
196
|
+
|
197
|
+
# This method is called by CouchStorage#by_field
|
198
|
+
#
|
199
|
+
def by_field (field, value=nil, opts={})
|
200
|
+
|
201
|
+
field = { field => value } if value
|
202
|
+
field = CGI.escape(Rufus::Json.encode(field))
|
203
|
+
|
204
|
+
query(
|
205
|
+
"_design/ruote/_view/by_field?key=#{field}" +
|
206
|
+
"&include_docs=true#{query_options(opts)}")
|
207
|
+
end
|
208
|
+
|
209
|
+
# This method is called by CouchStorage#by_participant
|
210
|
+
#
|
211
|
+
def by_participant (name, opts={})
|
212
|
+
|
213
|
+
query(
|
214
|
+
"_design/ruote/_view/by_participant_name?key=%22#{name}%22" +
|
215
|
+
"&include_docs=true#{query_options(opts)}")
|
216
|
+
end
|
217
|
+
|
218
|
+
protected
|
219
|
+
|
220
|
+
def design_doc
|
221
|
+
|
222
|
+
doc = super
|
223
|
+
|
224
|
+
# NOTE : with 'by_field', for a workitem with N fields there are
|
225
|
+
# currently 2 * N rows generated per workitem.
|
226
|
+
#
|
227
|
+
# Why not restrict { field => value } keys to only fields whose value
|
228
|
+
# is a string, a boolean or null ? I have the impression that querying
|
229
|
+
# for field whose value is 'complex' (array or hash) is not necessary
|
230
|
+
# (though sounding crazy useful).
|
231
|
+
|
232
|
+
doc['views']['by_field'] = {
|
233
|
+
'map' => %{
|
234
|
+
function(doc) {
|
235
|
+
if (doc.fields) {
|
236
|
+
for (var field in doc.fields) {
|
237
|
+
|
238
|
+
emit(field, null);
|
239
|
+
|
240
|
+
var k = {};
|
241
|
+
k[field] = doc.fields[field]
|
242
|
+
emit(k, null);
|
243
|
+
//
|
244
|
+
// have to use that k trick...
|
245
|
+
// else the field is named 'field'
|
246
|
+
}
|
247
|
+
}
|
248
|
+
}
|
249
|
+
}
|
250
|
+
}
|
251
|
+
doc['views']['by_participant_name'] = {
|
252
|
+
'map' => %{
|
253
|
+
function (doc) {
|
254
|
+
if (doc.participant_name) {
|
255
|
+
emit(doc.participant_name, null);
|
256
|
+
}
|
257
|
+
}
|
258
|
+
}
|
259
|
+
}
|
260
|
+
|
261
|
+
doc
|
151
262
|
end
|
152
263
|
end
|
153
264
|
end
|
data/lib/ruote/couch/storage.rb
CHANGED
@@ -55,15 +55,15 @@ module Couch
|
|
55
55
|
@host, @port, type, "#{@prefix}ruote_#{type}")
|
56
56
|
end
|
57
57
|
|
58
|
-
|
59
|
-
|
60
|
-
@dbs[type] = WfidIndexedDatabase.new(
|
61
|
-
@host, @port, type, "#{@prefix}ruote_#{type}")
|
62
|
-
end
|
58
|
+
@dbs['errors'] = WfidIndexedDatabase.new(
|
59
|
+
@host, @port, 'errors', "#{@prefix}ruote_errors")
|
63
60
|
|
64
61
|
@dbs['expressions'] = WfidIndexedDatabase.new(
|
65
62
|
@host, @port, 'expressions', "#{@prefix}ruote_expressions", false)
|
66
63
|
|
64
|
+
@dbs['workitems'] = WorkitemDatabase.new(
|
65
|
+
@host, @port, 'workitems', "#{@prefix}ruote_workitems")
|
66
|
+
|
67
67
|
put_configuration
|
68
68
|
end
|
69
69
|
|
@@ -128,6 +128,23 @@ module Couch
|
|
128
128
|
end
|
129
129
|
end
|
130
130
|
|
131
|
+
# A provision made for workitems, allow to query them directly by
|
132
|
+
# participant name.
|
133
|
+
#
|
134
|
+
def by_participant (type, participant_name)
|
135
|
+
|
136
|
+
raise NotImplementedError if type != 'workitems'
|
137
|
+
|
138
|
+
@dbs['workitems'].by_participant(participant_name)
|
139
|
+
end
|
140
|
+
|
141
|
+
def by_field (type, field, value=nil)
|
142
|
+
|
143
|
+
raise NotImplementedError if type != 'workitems'
|
144
|
+
|
145
|
+
@dbs['workitems'].by_field(field, value)
|
146
|
+
end
|
147
|
+
|
131
148
|
protected
|
132
149
|
|
133
150
|
def put_configuration
|
@@ -138,20 +155,6 @@ module Couch
|
|
138
155
|
|
139
156
|
put(conf)
|
140
157
|
end
|
141
|
-
|
142
|
-
# def put_design_document
|
143
|
-
#
|
144
|
-
# doc = Rufus::Jig::Json.decode(
|
145
|
-
# File.read(File.join(File.dirname(__FILE__), 'storage.json')))
|
146
|
-
#
|
147
|
-
# current = @couch.get('_design/ruote')
|
148
|
-
#
|
149
|
-
# if current.nil? || doc['version'] >= (current['version'] || -1)
|
150
|
-
#
|
151
|
-
# @couch.delete(current) if current
|
152
|
-
# @couch.put(doc)
|
153
|
-
# end
|
154
|
-
# end
|
155
158
|
end
|
156
159
|
end
|
157
160
|
end
|
data/lib/ruote/couch/version.rb
CHANGED
data/ruote-couch.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{ruote-couch}
|
8
|
-
s.version = "2.1.
|
8
|
+
s.version = "2.1.5"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["John Mettraux"]
|
12
|
-
s.date = %q{2010-01-
|
12
|
+
s.date = %q{2010-01-28}
|
13
13
|
s.description = %q{CouchDB storage for ruote 2.1 (ruby workflow engine)}
|
14
14
|
s.email = %q{jmettraux@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -52,17 +52,17 @@ Gem::Specification.new do |s|
|
|
52
52
|
s.specification_version = 3
|
53
53
|
|
54
54
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
55
|
-
s.add_runtime_dependency(%q<ruote>, [">= 2.1.
|
56
|
-
s.add_runtime_dependency(%q<rufus-jig>, [">= 0.1.
|
55
|
+
s.add_runtime_dependency(%q<ruote>, [">= 2.1.5"])
|
56
|
+
s.add_runtime_dependency(%q<rufus-jig>, [">= 0.1.12"])
|
57
57
|
s.add_development_dependency(%q<yard>, [">= 0"])
|
58
58
|
else
|
59
|
-
s.add_dependency(%q<ruote>, [">= 2.1.
|
60
|
-
s.add_dependency(%q<rufus-jig>, [">= 0.1.
|
59
|
+
s.add_dependency(%q<ruote>, [">= 2.1.5"])
|
60
|
+
s.add_dependency(%q<rufus-jig>, [">= 0.1.12"])
|
61
61
|
s.add_dependency(%q<yard>, [">= 0"])
|
62
62
|
end
|
63
63
|
else
|
64
|
-
s.add_dependency(%q<ruote>, [">= 2.1.
|
65
|
-
s.add_dependency(%q<rufus-jig>, [">= 0.1.
|
64
|
+
s.add_dependency(%q<ruote>, [">= 2.1.5"])
|
65
|
+
s.add_dependency(%q<rufus-jig>, [">= 0.1.12"])
|
66
66
|
s.add_dependency(%q<yard>, [">= 0"])
|
67
67
|
end
|
68
68
|
end
|
data/test/unit/ut_0_initial.rb
CHANGED
@@ -6,16 +6,14 @@
|
|
6
6
|
#
|
7
7
|
|
8
8
|
require File.join(File.dirname(__FILE__), '..', 'test_helper.rb')
|
9
|
-
|
10
|
-
require 'ruote/couch/storage'
|
9
|
+
require File.join(File.dirname(__FILE__), '..', 'integration_connection.rb')
|
11
10
|
|
12
11
|
|
13
12
|
class UtInitialTest < Test::Unit::TestCase
|
14
13
|
|
15
14
|
def test_connect
|
16
15
|
|
17
|
-
storage =
|
18
|
-
'127.0.0.1', 5984, :prefix => 'test')
|
16
|
+
storage = new_storage(nil)
|
19
17
|
|
20
18
|
v = storage.get_many('configurations')
|
21
19
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruote-couch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.
|
4
|
+
version: 2.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Mettraux
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-01-
|
12
|
+
date: 2010-01-28 00:00:00 +09:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -20,7 +20,7 @@ dependencies:
|
|
20
20
|
requirements:
|
21
21
|
- - ">="
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version: 2.1.
|
23
|
+
version: 2.1.5
|
24
24
|
version:
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rufus-jig
|
@@ -30,7 +30,7 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.1.
|
33
|
+
version: 0.1.12
|
34
34
|
version:
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
36
|
name: yard
|