Sha256: a68aa3a805e3b080415031adc52ae860d10d6054749d91abb0dae7d8be37e304

Contents?: true

Size: 1.12 KB

Versions: 2

Compression:

Stored size: 1.12 KB

Contents

require 'couchbase'

module CouchbaseModelLogging

  class Client

    attr_accessor :host, :port, :pool, :bucket, :protocol

    def initialize(options = { })
      self.protocol = options[:protocol] || 'http'
      self.host     = options[:host] || 'localhost'
      self.port     = options[:port] || 8091
      self.pool     = options[:pool] || 'default'
      self.bucket   = options[:bucket] || 'default'
    end

    def url
      "#{protocol}://#{host}:#{port}/pools/#{pool}/buckets/#{bucket}"
    end

    def native_client
      @native_client ||= ::Couchbase.connect url
    end

    def respond_to?(meth)
      native_client.respond_to?(meth) || super
    end

    def method_missing(meth, *args, &blk)
      if native_client.respond_to? meth
        call_info = caller[0] =~ /\/([\w\.]+):(\d+):in `(\w+)'/ ? "#{$1}:#{$2} #{$3}" : "unknown"
        #puts "mm : #{meth} : #{args.inspect} | from #{call_info}"
        native_client.send meth, *args, &blk
      else
        super
      end
    end

    alias_method :decorator_methods, :methods

    def methods
      (decorator_methods + native_client.methods).uniq
    end

  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
couchbase_model_logging-0.0.3 lib/couchbase_model_logging/client.rb
couchbase_model_logging-0.0.2 lib/couchbase_model_logging/client.rb