couchbase-jruby-client 0.1.0-java → 0.1.5-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/.jrubyrc +722 -0
  3. data/.ruby-version +1 -1
  4. data/README.md +12 -90
  5. data/couchbase-jruby-client.gemspec +6 -6
  6. data/lib/couchbase/async.rb +18 -0
  7. data/lib/couchbase/bucket.rb +90 -180
  8. data/lib/couchbase/constants.rb +17 -0
  9. data/lib/couchbase/design_doc.rb +83 -0
  10. data/lib/couchbase/error.rb +31 -0
  11. data/lib/couchbase/operations/arithmetic.rb +17 -0
  12. data/lib/couchbase/operations/delete.rb +17 -0
  13. data/lib/couchbase/operations/design_docs.rb +99 -0
  14. data/lib/couchbase/operations/get.rb +73 -67
  15. data/lib/couchbase/operations/stats.rb +28 -1
  16. data/lib/couchbase/operations/store.rb +114 -97
  17. data/lib/couchbase/operations/touch.rb +49 -19
  18. data/lib/couchbase/operations/unlock.rb +209 -0
  19. data/lib/couchbase/operations/utils.rb +22 -10
  20. data/lib/couchbase/operations.rb +21 -0
  21. data/lib/couchbase/query.rb +92 -0
  22. data/lib/couchbase/result.rb +18 -1
  23. data/lib/couchbase/transcoder.rb +36 -42
  24. data/lib/couchbase/version.rb +18 -1
  25. data/lib/couchbase/view.rb +30 -172
  26. data/lib/couchbase/view_row.rb +38 -98
  27. data/lib/couchbase.rb +74 -72
  28. data/test/profile/.jrubyrc +722 -0
  29. data/test/profile/Gemfile +5 -5
  30. data/test/profile/benchmark.rb +106 -124
  31. data/test/profile/profile.rb +59 -0
  32. data/test/setup.rb +10 -145
  33. data/test/test_arithmetic.rb +54 -77
  34. data/test/test_async.rb +74 -102
  35. data/test/test_bucket.rb +74 -60
  36. data/test/test_cas.rb +10 -23
  37. data/test/test_couchbase.rb +11 -3
  38. data/test/test_delete.rb +41 -43
  39. data/test/test_design_docs.rb +62 -0
  40. data/test/test_errors.rb +9 -18
  41. data/test/test_format.rb +21 -31
  42. data/test/test_get.rb +107 -151
  43. data/test/test_query.rb +23 -0
  44. data/test/test_stats.rb +9 -24
  45. data/test/test_store.rb +52 -65
  46. data/test/test_timer.rb +4 -12
  47. data/test/test_touch.rb +26 -33
  48. data/test/test_unlock.rb +47 -78
  49. data/test/test_utils.rb +2 -11
  50. data/test/test_version.rb +5 -14
  51. data/test/test_view.rb +87 -0
  52. metadata +27 -14
  53. data/lib/couchbase/jruby/couchbase_client.rb +0 -22
  54. data/lib/couchbase/jruby/future.rb +0 -8
@@ -1,9 +1,28 @@
1
+ # Author:: Mike Evans <mike@urlgonomics.com>
2
+ # Copyright:: 2013 Urlgonomics LLC.
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
1
18
  require 'couchbase/operations/touch'
2
19
  require 'couchbase/operations/store'
3
20
  require 'couchbase/operations/get'
4
21
  require 'couchbase/operations/delete'
22
+ require 'couchbase/operations/unlock'
5
23
  require 'couchbase/operations/arithmetic'
6
24
  require 'couchbase/operations/stats'
25
+ require 'couchbase/operations/design_docs'
7
26
  require 'couchbase/operations/utils'
8
27
 
9
28
  module Couchbase
@@ -14,8 +33,10 @@ module Couchbase
14
33
  klass.send(:include, Get)
15
34
  klass.send(:include, Touch)
16
35
  klass.send(:include, Delete)
36
+ klass.send(:include, Unlock)
17
37
  klass.send(:include, Arithmetic)
18
38
  klass.send(:include, Stats)
39
+ klass.send(:include, DesignDocs)
19
40
  klass.send(:include, Utils)
20
41
  end
21
42
  end
@@ -0,0 +1,92 @@
1
+ # Author:: Mike Evans <mike@urlgonomics.com>
2
+ # Copyright:: 2013 Urlgonomics LLC.
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+
19
+ module Couchbase
20
+ class Query
21
+
22
+ java_import com.couchbase.client.protocol.views.Stale
23
+
24
+ METHOD_MAPPING = {
25
+ :include_docs => :setIncludeDocs,
26
+ :descending => :setDescending,
27
+ :key => :setKey,
28
+ :keys => :setKeys,
29
+ :start_key => :setRangeStart,
30
+ :startkey => :setRangeStart,
31
+ :startkey_docid => :setStartkeyDocID,
32
+ :endkey => :setRangeEnd,
33
+ :endkey_docid => :setEndkeyDocID,
34
+ :inclusive_end => :setInclusiveEnd,
35
+ :limit => :setLimit,
36
+ :skip => :setSkip,
37
+ :reduce => :setReduce,
38
+ :group => :setGroup,
39
+ :group_level => :setGroupLevel,
40
+ :connection_timeout => nil
41
+ }.freeze
42
+
43
+ def initialize(params)
44
+ @params = params
45
+ end
46
+
47
+ def generate
48
+ query = Java::ComCouchbaseClientProtocolViews::Query.new
49
+
50
+ stale = @params.delete(:stale)
51
+ if !stale.nil?
52
+ case stale
53
+ when :after_update
54
+ query.setStale(Stale::UPDATE_AFTER)
55
+ when :ok
56
+ query.setStale(Stale::OK)
57
+ when false
58
+ query.setStale(Stale::FALSE)
59
+ end
60
+ end
61
+
62
+ @params.each_pair do |meth, val|
63
+ if METHOD_MAPPING.key?(meth)
64
+ if java_meth = METHOD_MAPPING[meth]
65
+ query.send(java_meth, val)
66
+ end
67
+ else
68
+ fail ArgumentError, "Query does not support #{meth}"
69
+ end
70
+ end
71
+
72
+
73
+ # @option params [true, false] :quiet (true) Do not raise error if
74
+ # associated document not found in the memory. If the parameter +true+
75
+ # will use +nil+ value instead.
76
+ # @option params [String, Symbol] :on_error (:continue) Sets the
77
+ # response in the event of an error. Supported values:
78
+ # :continue:: Continue to generate view information in the event of an
79
+ # error, including the error information in the view
80
+ # response stream.
81
+ # :stop:: Stop immediately when an error condition occurs. No
82
+ # further view information will be returned.
83
+ # @option params [Fixnum] :connection_timeout (75000) Timeout before the
84
+ # view request is dropped (milliseconds)
85
+
86
+
87
+ # @option params [Hash] :body
88
+ query
89
+ end
90
+
91
+ end
92
+ end
@@ -1,3 +1,20 @@
1
+ # Author:: Mike Evans <mike@urlgonomics.com>
2
+ # Copyright:: 2013 Urlgonomics LLC.
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
1
18
  module Couchbase
2
19
  class Result
3
20
 
@@ -27,7 +44,7 @@ module Couchbase
27
44
  end
28
45
 
29
46
  def value
30
- @bucket.load @future.get
47
+ @future.get
31
48
  rescue MultiJson::LoadError
32
49
  nil
33
50
  end
@@ -21,60 +21,54 @@ module Couchbase
21
21
 
22
22
  module Transcoder
23
23
 
24
- # module Compat
25
- # def self.enable!
26
- # @disabled = false
27
- # end
28
-
29
- # def self.disable!
30
- # @disabled = true
31
- # end
32
-
33
- # def self.enabled?
34
- # !@disabled
35
- # end
36
-
37
- # def self.guess_and_load(blob, flags, options = {})
38
- # case flags & Bucket::FMT_MASK
39
- # when Bucket::FMT_DOCUMENT
40
- # MultiJson.load(blob)
41
- # when Bucket::FMT_MARSHAL
42
- # ::Marshal.load(blob)
43
- # when Bucket::FMT_PLAIN
44
- # blob
45
- # else
46
- # raise ArgumentError, "unexpected flags (0x%02x)" % flags
47
- # end
48
- # end
49
- # end
50
-
51
- module Document
52
- def self.dump(obj)
53
- MultiJson.dump(obj)
24
+ class Base < Java::NetSpyMemcachedTranscoders::SerializingTranscoder
25
+ end
26
+
27
+ class Document < Base
28
+
29
+ def decode(d)
30
+ decoded = super
31
+ data = if decoded.respond_to?(:to_str)
32
+ decoded
33
+ else
34
+ decoded.getData.to_s
35
+ end
36
+
37
+ MultiJson.load(data)
38
+ rescue MultiJson::LoadError
39
+ ::Marshal.load(data)
54
40
  end
55
41
 
56
- def self.load(blob)
57
- MultiJson.load(blob)
42
+ def encode(o)
43
+ super MultiJson.dump(o)
44
+ rescue ArgumentError => e
45
+ ex = Couchbase::Error::ValueFormat.new
46
+ ex.inner_exception = e
47
+ fail ex
58
48
  end
59
49
  end
60
50
 
61
- module Marshal
62
- def self.dump(obj)
63
- ::Marshal.dump(obj)
51
+ class Marshal < Base
52
+
53
+ def decode(d)
54
+ ::Marshal.load super.getData.to_s
64
55
  end
65
56
 
66
- def self.load(blob)
67
- ::Marshal.load(blob)
57
+ def encode(o)
58
+ super ::Marshal.dump(o)
68
59
  end
69
60
  end
70
61
 
71
- module Plain
72
- def self.dump(obj)
73
- obj
62
+ class Plain < Base
63
+
64
+ def decode(d)
65
+ super
74
66
  end
75
67
 
76
- def self.load(blob)
77
- blob
68
+ def encode(o)
69
+ super(o.to_str)
70
+ rescue NoMethodError
71
+ raise Couchbase::Error::ValueFormat
78
72
  end
79
73
  end
80
74
 
@@ -1,3 +1,20 @@
1
+ # Author:: Mike Evans <mike@urlgonomics.com>
2
+ # Copyright:: 2013 Urlgonomics LLC.
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
1
18
  module Couchbase
2
- VERSION = '0.1.0'
19
+ VERSION = '0.1.5'
3
20
  end
@@ -63,6 +63,7 @@ module Couchbase
63
63
  #
64
64
  # @see http://www.couchbase.com/docs/couchbase-manual-2.0/couchbase-views.html
65
65
  class View
66
+
66
67
  include Enumerable
67
68
  include Constants
68
69
 
@@ -71,83 +72,7 @@ module Couchbase
71
72
  alias total_entries total_rows
72
73
  end
73
74
 
74
- class AsyncHelper # :nodoc:
75
- include Constants
76
- EMPTY = []
77
-
78
- def initialize(wrapper_class, bucket, include_docs, quiet, block)
79
- @wrapper_class = wrapper_class
80
- @bucket = bucket
81
- @block = block
82
- @quiet = quiet
83
- @include_docs = include_docs
84
- @queue = []
85
- @first = @shift = 0
86
- @completed = false
87
- end
88
-
89
- # Register object in the emitter.
90
- def push(obj)
91
- if @include_docs
92
- @queue << obj
93
- @bucket.get(obj[S_ID], :extended => true, :quiet => @quiet) do |res|
94
- obj[S_DOC] = {
95
- S_VALUE => res.value,
96
- S_META => {
97
- S_ID => obj[S_ID],
98
- S_FLAGS => res.flags,
99
- S_CAS => res.cas
100
- }
101
- }
102
- check_for_ready_documents
103
- end
104
- else
105
- old_obj = @queue.shift
106
- @queue << obj
107
- block_call(old_obj) if old_obj
108
- end
109
- end
110
-
111
- def complete!
112
- if @include_docs
113
- @completed = true
114
- check_for_ready_documents
115
- elsif !@queue.empty?
116
- obj = @queue.shift
117
- obj[S_IS_LAST] = true
118
- block_call obj
119
- end
120
- end
121
-
122
- private
123
-
124
- def block_call(obj)
125
- @block.call @wrapper_class.wrap(@bucket, obj)
126
- end
127
-
128
- def check_for_ready_documents
129
- shift = @shift
130
- queue = @queue
131
- save_last = @completed ? 0 : 1
132
- while @first < queue.size + shift - save_last
133
- obj = queue[@first - shift]
134
- break unless obj[S_DOC]
135
- queue[@first - shift] = nil
136
- @first += 1
137
- if @completed && @first == queue.size + shift
138
- obj[S_IS_LAST] = true
139
- end
140
- block_call obj
141
- end
142
- if @first - shift > queue.size / 2
143
- queue[0, @first - shift] = EMPTY
144
- @shift = @first
145
- end
146
- end
147
-
148
- end
149
-
150
- attr_reader :params
75
+ attr_reader :params, :design_doc, :name
151
76
 
152
77
  # Set up view endpoint and optional params
153
78
  #
@@ -160,10 +85,11 @@ module Couchbase
160
85
  # {View#fetch}
161
86
  #
162
87
  def initialize(bucket, endpoint, params = {})
163
- @bucket = bucket
88
+ @bucket = bucket
164
89
  @endpoint = endpoint
165
- @params = {:connection_timeout => 75_000}.merge(params)
90
+ @design_doc, @name = parse_endpoint(endpoint)
166
91
  @wrapper_class = params.delete(:wrapper_class) || ViewRow
92
+ @params = { connection_timeout: 75_000 }.merge(params)
167
93
  unless @wrapper_class.respond_to?(:wrap)
168
94
  raise ArgumentError, "wrapper class should reposond to :wrap, check the options"
169
95
  end
@@ -197,7 +123,7 @@ module Couchbase
197
123
  #
198
124
  def each(params = {})
199
125
  return enum_for(:each, params) unless block_given?
200
- fetch(params) {|doc| yield(doc)}
126
+ fetch(params) { |doc| yield(doc) }
201
127
  end
202
128
 
203
129
  def first(params = {})
@@ -357,25 +283,30 @@ module Couchbase
357
283
  # doc.recent_posts_with_comments(:start_key => [post_id, 0],
358
284
  # :end_key => [post_id, 1],
359
285
  # :include_docs => true)
360
- def fetch(params = {}, &block)
286
+ def fetch(params = {})
361
287
  params = @params.merge(params)
362
- include_docs = params.delete(:include_docs)
363
- quiet = params.delete(:quiet){ true }
288
+ # quiet = params.fetch(:quiet, true)
364
289
 
365
- options = {:chunked => true, :extended => true, :type => :view}
366
- if body = params.delete(:body)
367
- body = MultiJson.dump(body) unless body.is_a?(String)
368
- options.update(:body => body, :method => params.delete(:method) || :post)
369
- end
370
- path = Utils.build_query(@endpoint, params)
371
- request = @bucket.make_http_request(path, options)
290
+ view = @bucket.client.getView(@design_doc, @name)
291
+
292
+ query = Query.new(params)
372
293
 
373
- if @bucket.async?
374
- if block
375
- fetch_async(request, include_docs, quiet, block)
294
+ request = @bucket.client.query(view, query.generate)
295
+
296
+ if block_given?
297
+ block = Proc.new
298
+ request.each do |data|
299
+ doc = @wrapper_class.wrap(@bucket, data)
300
+ block.call(doc)
376
301
  end
302
+ nil
377
303
  else
378
- fetch_sync(request, include_docs, quiet, block)
304
+ docs = request.to_a.map { |data|
305
+ @wrapper_class.wrap(@bucket, data)
306
+ }
307
+ docs = ArrayWithTotalRows.new(docs)
308
+ docs.total_rows = request.size
309
+ docs
379
310
  end
380
311
  end
381
312
 
@@ -421,86 +352,13 @@ module Couchbase
421
352
  end
422
353
  end
423
354
 
424
- def fetch_async(request, include_docs, quiet, block)
425
- filter = ["/rows/", "/errors/"]
426
- parser = YAJI::Parser.new(:filter => filter, :with_path => true)
427
- helper = AsyncHelper.new(@wrapper_class, @bucket, include_docs, quiet, block)
428
-
429
- request.on_body do |chunk|
430
- if chunk.success?
431
- parser << chunk.value if chunk.value
432
- helper.complete! if chunk.completed?
433
- else
434
- send_error("http_error", chunk.error)
435
- end
436
- end
437
-
438
- parser.on_object do |path, obj|
439
- case path
440
- when "/errors/"
441
- from, reason = obj["from"], obj["reason"]
442
- send_error(from, reason)
443
- else
444
- helper.push(obj)
445
- end
446
- end
447
-
448
- request.perform
449
- nil
450
- end
451
-
452
- def fetch_sync(request, include_docs, quiet, block)
453
- res = []
454
- filter = ["/rows/", "/errors/"]
455
- unless block
456
- filter << "/total_rows"
457
- docs = ArrayWithTotalRows.new
458
- end
459
- parser = YAJI::Parser.new(:filter => filter, :with_path => true)
460
- last_chunk = nil
461
-
462
- request.on_body do |chunk|
463
- last_chunk = chunk
464
- res << chunk.value if chunk.success?
465
- end
466
-
467
- parser.on_object do |path, obj|
468
- case path
469
- when "/total_rows"
470
- # if total_rows key present, save it and take next object
471
- docs.total_rows = obj
472
- when "/errors/"
473
- from, reason = obj["from"], obj["reason"]
474
- send_error(from, reason)
475
- else
476
- if include_docs
477
- val, flags, cas = @bucket.get(obj[S_ID], :extended => true, :quiet => quiet)
478
- obj[S_DOC] = {
479
- S_VALUE => val,
480
- S_META => {
481
- S_ID => obj[S_ID],
482
- S_FLAGS => flags,
483
- S_CAS => cas
484
- }
485
- }
486
- end
487
- doc = @wrapper_class.wrap(@bucket, obj)
488
- block ? block.call(doc) : docs << doc
489
- end
490
- end
491
-
492
- request.continue
493
-
494
- if last_chunk.success?
495
- while value = res.shift
496
- parser << value
497
- end
355
+ def parse_endpoint(endpoint)
356
+ parts = endpoint.split('/')
357
+ if endpoint =~ /^_design/
358
+ [parts[1], parts[3]]
498
359
  else
499
- send_error("http_error", last_chunk.error, nil)
360
+ [parts[0], parts[2]]
500
361
  end
501
-
502
- # return nil for call with block
503
- docs
504
362
  end
505
363
  end
506
364
  end
@@ -16,6 +16,31 @@
16
16
  #
17
17
 
18
18
  module Couchbase
19
+
20
+ java_import com.couchbase.client.protocol.views.ViewRowNoDocs
21
+ java_import com.couchbase.client.protocol.views.ViewRowWithDocs
22
+ java_import com.couchbase.client.protocol.views.ViewRowReduced
23
+ java_import com.couchbase.client.protocol.views.SpatialViewRowNoDocs
24
+ java_import com.couchbase.client.protocol.views.SpatialViewRowWithDocs
25
+
26
+ module Java::ComCouchbaseClientProtocolViews::ViewRow
27
+
28
+ def doc
29
+ {
30
+ 'meta' => nil,
31
+ 'value' => document
32
+ }
33
+ end
34
+
35
+ def [](key)
36
+ if respond_to?(key)
37
+ send(key)
38
+ else
39
+ fail NoMethodError, "ViewRow##{key} isn't defined."
40
+ end
41
+ end
42
+ end
43
+
19
44
  # This class encapsulates structured JSON document
20
45
  #
21
46
  # @since 1.2.0
@@ -24,6 +49,7 @@ module Couchbase
24
49
  #
25
50
  # @see http://www.couchbase.com/docs/couchbase-manual-2.0/couchbase-views-datastore.html
26
51
  class ViewRow
52
+
27
53
  include Constants
28
54
 
29
55
  # Undefine as much methods as we can to free names for views
@@ -95,15 +121,19 @@ module Couchbase
95
121
  # representation
96
122
  def initialize(bucket, data)
97
123
  @bucket = bucket
98
- @data = data
99
- @key = data[S_KEY]
100
- @value = data[S_VALUE]
101
- if data[S_DOC]
102
- @meta = data[S_DOC][S_META]
103
- @doc = data[S_DOC][S_VALUE]
124
+ @data = data
125
+ @key = data.key
126
+ @value = data.value
127
+ @id = data.id
128
+ @last = false
129
+
130
+ case data
131
+ when ViewRowWithDocs, SpatialViewRowWithDocs
132
+ @doc = data.document
133
+ when SpatialViewRowNoDocs, SpatialViewRowWithDocs
134
+ @geometry = data.geometry
135
+ @bbox = data.bbox
104
136
  end
105
- @id = data[S_ID] || @meta && @meta[S_ID]
106
- @last = data.delete(S_IS_LAST) || false
107
137
  end
108
138
 
109
139
  # Wraps data hash into ViewRow instance
@@ -179,94 +209,4 @@ module Couchbase
179
209
  end
180
210
  end
181
211
 
182
- # This class encapsulates information about design docs
183
- #
184
- # @since 1.2.1
185
- #
186
- # It is subclass of ViewRow, but also gives access to view creation through method_missing
187
- #
188
- # @see http://www.couchbase.com/docs/couchbase-manual-2.0/couchbase-views-datastore.html
189
- class DesignDoc < ViewRow
190
- # It isn't allowed to change design document ID after
191
- # initialization
192
- undef id=
193
-
194
- # Initialize the design doc instance
195
- #
196
- # @since 1.2.1
197
- #
198
- # It takes reference to the bucket, data hash. It will define view
199
- # methods if the data object looks like design document.
200
- #
201
- # @param [Couchbase::Bucket] bucket the reference to connection
202
- # @param [Hash] data the data hash, which was built from JSON document
203
- # representation
204
- def initialize(bucket, data)
205
- super
206
- @all_views = {}
207
- @views = @doc.has_key?('views') ? @doc['views'].keys : []
208
- @spatial = @doc.has_key?('spatial') ? @doc['spatial'].keys : []
209
- @views.each{|name| @all_views[name] = "#{@id}/_view/#{name}"}
210
- @spatial.each{|name| @all_views[name] = "#{@id}/_spatial/#{name}"}
211
- end
212
-
213
- def method_missing(meth, *args)
214
- if path = @all_views[meth.to_s]
215
- View.new(@bucket, path, *args)
216
- else
217
- super
218
- end
219
- end
220
-
221
- def respond_to?(meth, *args)
222
- if @all_views[meth.to_s]
223
- true
224
- else
225
- super
226
- end
227
- end
228
-
229
- def method(meth, *args)
230
- if path = @all_views[meth.to_s]
231
- lambda{|*p| View.new(@bucket, path, *p)}
232
- else
233
- super
234
- end
235
- end
236
-
237
- # The list of views defined or empty array
238
- #
239
- # @since 1.2.1
240
- #
241
- # @return [Array<View>]
242
- attr_accessor :views
243
-
244
- # The list of spatial views defined or empty array
245
- #
246
- # @since 1.2.1
247
- #
248
- # @return [Array<View>]
249
- attr_accessor :spatial
250
-
251
- # Check if the document has views defines
252
- #
253
- # @since 1.2.1
254
- #
255
- # @see DesignDoc#views
256
- #
257
- # @return [true, false] +true+ if the document have views
258
- def has_views?
259
- !@views.empty?
260
- end
261
-
262
- def inspect
263
- desc = "#<#{self.class.name}:#{self.object_id}"
264
- [:@id, :@views, :@spatial].each do |iv|
265
- desc << " #{iv}=#{instance_variable_get(iv).inspect}"
266
- end
267
- desc << ">"
268
- desc
269
- end
270
-
271
- end
272
212
  end