Class: CouchbaseOrm::CollectionProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/couchbase-orm/proxies/collection_proxy.rb

Instance Method Summary collapse

Constructor Details

#initialize(proxyfied) ⇒ CollectionProxy

Returns a new instance of CollectionProxy.

Raises:

  • (ArgumentError)


66
67
68
69
70
# File 'lib/couchbase-orm/proxies/collection_proxy.rb', line 66

def initialize(proxyfied)
  raise ArgumentError.new('Must proxy a non nil object') if proxyfied.nil?

  @proxyfied = proxyfied
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object

:nocov:



77
78
79
# File 'lib/couchbase-orm/proxies/collection_proxy.rb', line 77

def method_missing(name, *args, **options, &block)
  @proxyfied.public_send(name, *args, **options, &block)
end

Instance Method Details

#get(id, **options) ⇒ Object



11
12
13
14
15
# File 'lib/couchbase-orm/proxies/collection_proxy.rb', line 11

def get(id, **options)
  @proxyfied.get(id, Couchbase::Options::Get.new(**options))
rescue Couchbase::Error::DocumentNotFound
  nil
end

#get!(id, **options) ⇒ Object



7
8
9
# File 'lib/couchbase-orm/proxies/collection_proxy.rb', line 7

def get!(id, **options)
  @proxyfied.get(id, Couchbase::Options::Get.new(**options))
end

#get_multi(*ids, **options) ⇒ Object



25
26
27
28
# File 'lib/couchbase-orm/proxies/collection_proxy.rb', line 25

def get_multi(*ids, **options)
  result = @proxyfied.get_multi(*ids, Couchbase::Options::GetMulti.new(**options))
  result.reject(&:error)
end

#get_multi!(*ids, **options) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/couchbase-orm/proxies/collection_proxy.rb', line 17

def get_multi!(*ids, **options)
  result = @proxyfied.get_multi(*ids, Couchbase::Options::GetMulti.new(**options))
  first_result_with_error = result.find(&:error)
  raise first_result_with_error.error if first_result_with_error

  result
end

#remove(id, **options) ⇒ Object



34
35
36
37
38
# File 'lib/couchbase-orm/proxies/collection_proxy.rb', line 34

def remove(id, **options)
  @proxyfied.remove(id, Couchbase::Options::Remove.new(**options))
rescue Couchbase::Error::DocumentNotFound
  nil
end

#remove!(id, **options) ⇒ Object



30
31
32
# File 'lib/couchbase-orm/proxies/collection_proxy.rb', line 30

def remove!(id, **options)
  @proxyfied.remove(id, Couchbase::Options::Remove.new(**options))
end

#remove_multi(ids, **options) ⇒ Object



48
49
50
51
# File 'lib/couchbase-orm/proxies/collection_proxy.rb', line 48

def remove_multi(ids, **options)
  result = @proxyfied.remove_multi(ids, Couchbase::Options::RemoveMulti.new(**options))
  result.reject(&:error)
end

#remove_multi!(ids, **options) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/couchbase-orm/proxies/collection_proxy.rb', line 40

def remove_multi!(ids, **options)
  result = @proxyfied.remove_multi(ids, Couchbase::Options::RemoveMulti.new(**options))
  first_result_with_error = result.find(&:error)
  raise first_result_with_error.error if first_result_with_error

  result
end

#upsert_multi(id_content, **options) ⇒ Object



61
62
63
64
# File 'lib/couchbase-orm/proxies/collection_proxy.rb', line 61

def upsert_multi(id_content, **options)
  result = @proxyfied.upsert_multi(id_content, Couchbase::Options::UpsertMulti.new(**options))
  result.reject(&:error)
end

#upsert_multi!(id_content, **options) ⇒ Object



53
54
55
56
57
58
59
# File 'lib/couchbase-orm/proxies/collection_proxy.rb', line 53

def upsert_multi!(id_content, **options)
  result = @proxyfied.upsert_multi(id_content, Couchbase::Options::UpsertMulti.new(**options))
  first_result_with_error = result.find(&:error)
  raise first_result_with_error.error if first_result_with_error

  result
end