Class: CouchbaseOrm::BucketProxy

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

Instance Method Summary collapse

Constructor Details

#initialize(proxyfied) ⇒ BucketProxy

Returns a new instance of BucketProxy.

Raises:

  • (ArgumentError)


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/couchbase-orm/proxies/bucket_proxy.rb', line 8

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

  @proxyfied = proxyfied

  self.class.define_method(:n1ql) do
    N1qlProxy.new(@proxyfied.n1ql)
  end

  self.class.define_method(:view) do |design, view, **opts, &block|
    @results = nil if @current_query != "#{design}_#{view}"
    @current_query = "#{design}_#{view}"
    return @results if @results

    CouchbaseOrm.logger.debug "View - #{design} #{view}"
    @results = ResultsProxy.new(@proxyfied.send(:view, design, view, **opts, &block))
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



28
29
30
# File 'lib/couchbase-orm/proxies/bucket_proxy.rb', line 28

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