Class: Couchbase

Inherits:
Object
  • Object
show all
Defined in:
lib/jcouchbase/jcouchbase.rb,
lib/jcouchbase/version.rb

Overview

Copyright © 2012 Jeremy Brenner

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in coSmpliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Constant Summary collapse

VERSION =
'0.1.4'
Observer =
java.util.Observer

Instance Method Summary collapse

Constructor Details

#initialize(pool_uris, bucket, password = '') ⇒ Couchbase

Returns a new instance of Couchbase.



58
59
60
61
62
63
64
65
# File 'lib/jcouchbase/jcouchbase.rb', line 58

def initialize(pool_uris, bucket, password='')
  @urilist = ArrayList.new
  pool_uris = [ pool_uris ] if pool_uris.is_a? String
  pool_uris.each { |uri| @urilist << URI.new(uri) }
  @bucket = bucket
  @password = password
  self.connect
end

Instance Method Details

#[](key) ⇒ Object



109
110
111
# File 'lib/jcouchbase/jcouchbase.rb', line 109

def [] ( key )
  self.get( key )
end

#[]=(key, value) ⇒ Object



105
106
107
# File 'lib/jcouchbase/jcouchbase.rb', line 105

def []= ( key, value )
  self.set( key, 0, value )
end

#connectObject



67
68
69
70
71
# File 'lib/jcouchbase/jcouchbase.rb', line 67

def connect
  @connection_factory = CouchbaseConnectionFactory.new( @urilist, @bucket.to_java_string, @password.to_java_string )
  @client = CouchbaseClient.new(@connection_factory)
  self
end

#javify(o) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
# File 'lib/jcouchbase/jcouchbase.rb', line 73

def javify(o)
  if( o.is_a? Hash )
    o.each { |k,v| o[k] = self.javify(v) }
    return java.util.HashMap.new( o )
  end
  if( o.is_a? Array )
     o.each_index { |i| o[i] = self.javify( o[i] ) }
     return java.util.ArrayList.new( o )
  end
  return o
end

#rubify(o) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/jcouchbase/jcouchbase.rb', line 85

def rubify(o)
  if( o.is_a? Java::JavaUtil::HashMap )
    h = {}
    o.each { |k,v| h[k] = self.rubify(v) }
    return h
  end
  if( o.is_a? Java::JavaUtil::ArrayList )
     a = []
     o.each { |v| a << self.rubify(v) }
     return a
  end
  return o
end