Class: CouchbaseModelLogging::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/couchbase_model_logging/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = { }) ⇒ Client



9
10
11
12
13
14
15
16
17
# File 'lib/couchbase_model_logging/client.rb', line 9

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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &blk) ⇒ Object



39
40
41
42
43
44
45
46
47
# File 'lib/couchbase_model_logging/client.rb', line 39

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

Instance Attribute Details

#bucketObject

Returns the value of attribute bucket.



7
8
9
# File 'lib/couchbase_model_logging/client.rb', line 7

def bucket
  @bucket
end

#hostObject

Returns the value of attribute host.



7
8
9
# File 'lib/couchbase_model_logging/client.rb', line 7

def host
  @host
end

#passwordObject

Returns the value of attribute password.



7
8
9
# File 'lib/couchbase_model_logging/client.rb', line 7

def password
  @password
end

#poolObject

Returns the value of attribute pool.



7
8
9
# File 'lib/couchbase_model_logging/client.rb', line 7

def pool
  @pool
end

#portObject

Returns the value of attribute port.



7
8
9
# File 'lib/couchbase_model_logging/client.rb', line 7

def port
  @port
end

#protocolObject

Returns the value of attribute protocol.



7
8
9
# File 'lib/couchbase_model_logging/client.rb', line 7

def protocol
  @protocol
end

#usernameObject

Returns the value of attribute username.



7
8
9
# File 'lib/couchbase_model_logging/client.rb', line 7

def username
  @username
end

Instance Method Details

#connection_optionsObject



23
24
25
26
27
28
29
# File 'lib/couchbase_model_logging/client.rb', line 23

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

#decorator_methodsObject



49
# File 'lib/couchbase_model_logging/client.rb', line 49

alias_method :decorator_methods, :methods

#methodsObject



51
52
53
# File 'lib/couchbase_model_logging/client.rb', line 51

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

#native_clientObject



31
32
33
# File 'lib/couchbase_model_logging/client.rb', line 31

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

#respond_to?(meth) ⇒ Boolean



35
36
37
# File 'lib/couchbase_model_logging/client.rb', line 35

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

#urlObject



19
20
21
# File 'lib/couchbase_model_logging/client.rb', line 19

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