Sha256: 8a947a1c1fd13b94e8bd9846253390f199123a4be16faf32f1fec0d7d989a2eb

Contents?: true

Size: 1.41 KB

Versions: 4

Compression:

Stored size: 1.41 KB

Contents

require 'couchbase'

module CouchbaseModelLogging

  class Client

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

    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'
      self.username = options[:username]
      self.password = options[:password]
    end

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

    def connection_options
      options = {}
      options[:bucket] = bucket
      options[:username] = username if username
      options[:password] = password if password
      options
    end

    def native_client
      @native_client ||= ::Couchbase.connect url, connection_options
    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

4 entries across 4 versions & 1 rubygems

Version Path
couchbase_model_logging-0.0.7 lib/couchbase_model_logging/client.rb
couchbase_model_logging-0.0.6 lib/couchbase_model_logging/client.rb
couchbase_model_logging-0.0.5 lib/couchbase_model_logging/client.rb
couchbase_model_logging-0.0.4 lib/couchbase_model_logging/client.rb