couchbase-docstore 0.1.4 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,21 +1,31 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
4
5
  require 'couchbase_doc_store/version'
5
6
 
6
7
  Gem::Specification.new do |gem|
7
8
  gem.name = "couchbase-docstore"
8
- gem.version = CouchbaseDocStore::VERSION
9
+ gem.version = "0.3.0"
9
10
  gem.authors = ["Jasdeep Jaitla"]
10
11
  gem.email = ["jasdeep@scalabl3.com"]
11
12
  gem.description = %q{A Convenient Wrapper for the Couchbase gem, uses Map gem and adds new functionality}
12
13
  gem.summary = %q{You simply use the Couchbase gem, or you can use this wrapper that encapsulates the gem and adds some subjective conveniences. }
13
14
  gem.homepage = "https://github.com/scalabl3/couchbase-docstore"
14
15
 
15
- gem.add_dependency('couchbase-settings', '>= 0.1.0')
16
- gem.add_dependency('couchbase', '>= 1.2.0.z.beta3')
16
+ gem.add_dependency('couchbase-settings', '>= 0.2.7')
17
+ gem.add_dependency('couchbase', '>= 1.2')
17
18
 
18
- gem.files = `git ls-files`.split($/)
19
+ gem.files = [
20
+ "Gemfile",
21
+ "LICENSE.txt",
22
+ "README.md",
23
+ "Rakefile",
24
+ "lib/couchbase-docstore.rb",
25
+ "lib/couchbase_doc_store/railtie.rb",
26
+ "lib/couchbase_doc_store/version.rb",
27
+ "couchbase-docstore.gemspec"
28
+ ]
19
29
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
20
30
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
21
31
  gem.require_paths = ["lib"]
@@ -1,32 +1,10 @@
1
1
  require 'couchbase'
2
2
  require 'map'
3
- require 'couchbase_settings'
4
3
  require "couchbase_doc_store/version"
4
+ require "couchbase_doc_store/railtie" if defined?(Rails)
5
5
 
6
6
  module CouchbaseDocStore
7
7
 
8
- #Rails.logger.debug(CouchbaseSetting.pm)
9
-
10
- setting_hash = {}
11
- if (CouchbaseSetting.respond_to?("servers") && CouchbaseSetting.servers && !CouchbaseSetting.servers.empty?)
12
- setting_hash[:node_list] = CouchbaseSetting.servers
13
- elsif CouchbaseSetting.respond_to?("server")
14
-
15
- setting_hash[:hostname] = CouchbaseSetting.server
16
- else
17
- raise ArgumentError, "You didn't set a Couchbase Server in your /config/couchbase.yml file!"
18
- end
19
- setting_hash[:pool] = "default"
20
- setting_hash[:bucket] = CouchbaseSetting.bucket
21
- setting_hash[:port] = 8091
22
-
23
- if (CouchbaseSetting.respond_to?("password") && CouchbaseSetting.password && !CouchbaseSetting.password.blank?)
24
- setting_hash[:username] = CouchbaseSetting.bucket
25
- setting_hash[:password] = CouchbaseSetting.password
26
- end
27
-
28
- CB = Couchbase.connect(setting_hash)
29
-
30
8
  #### INSTANCE METHODS
31
9
 
32
10
  # Check if a key/document exists
@@ -93,57 +71,92 @@ module CouchbaseDocStore
93
71
  #### CLASS METHODS
94
72
 
95
73
  class << self
74
+
75
+ def connection
76
+ $cb
77
+ end
78
+
79
+ def connect!(setting_hash = {hostname: "127.0.0.1", bucket: "default"})
80
+ puts "---------------------------------------------------"
81
+ if defined? (CouchbaseSetting)
82
+
83
+ puts "CouchbaseSetting found..."
84
+
85
+ if (CouchbaseSetting.respond_to?("servers") && CouchbaseSetting.servers && !CouchbaseSetting.servers.empty?)
86
+ setting_hash[:node_list] = CouchbaseSetting.servers
87
+ elsif CouchbaseSetting.respond_to?("server")
88
+ setting_hash[:hostname] = CouchbaseSetting.server
89
+ else
90
+ raise ArgumentError, "You didn't set Couchbase Server(s)/Bucket in your /config/couchbase.yml file!"
91
+ end
92
+
93
+ setting_hash[:pool] = "default"
94
+ setting_hash[:bucket] = CouchbaseSetting.bucket
95
+ setting_hash[:port] = 8091
96
+
97
+ if (CouchbaseSetting.respond_to?("password") && CouchbaseSetting.password && !CouchbaseSetting.password.blank?)
98
+ setting_hash[:username] = CouchbaseSetting.bucket
99
+ setting_hash[:password] = CouchbaseSetting.password
100
+ end
101
+ end
96
102
 
103
+ $cb = Couchbase.connect(setting_hash)
104
+
105
+ puts "CouchbaseDocStore connected..."
106
+ puts $cb.inspect
107
+ puts "---------------------------------------------------"
108
+ end
109
+
97
110
  def delete_all_documents!
98
- CB.flush
111
+ $cb.flush
99
112
  end
100
113
 
101
114
  def document_exists?(key)
102
115
  return nil unless key
103
116
 
104
117
  # Save quiet setting
105
- tmp = CB.quiet
118
+ tmp = $cb.quiet
106
119
 
107
120
  # Set quiet to be sure
108
- CB.quiet = true
121
+ $cb.quiet = true
109
122
 
110
- doc = CB.get(key)
123
+ doc = $cb.get(key)
111
124
 
112
125
  # Restore quiet setting
113
- CB.quiet = tmp
126
+ $cb.quiet = tmp
114
127
 
115
128
  !doc.nil?
116
129
  end
117
130
 
118
131
  def initialize_document(key, value, args={})
119
132
  return nil unless key
120
- CB.quiet = true
133
+ $cb.quiet = true
121
134
  doc = CouchbaseDocStore.get_document( key )
122
- (value.is_a?(Fixnum) || value.is_a?(Integer) ? CB.set( key, value ) : CB.add( key, value )) unless doc
135
+ (value.is_a?(Fixnum) || value.is_a?(Integer) ? $cb.set( key, value ) : $cb.add( key, value )) unless doc
123
136
  end
124
137
 
125
138
  def create_document(key, value, args={})
126
139
  return nil unless key
127
- CB.quiet = args[:quiet] || true
128
- CB.add(key, value, args) # => if !quiet, Generates Couchbase::Error::KeyExists if key already exists
140
+ $cb.quiet = args[:quiet] || true
141
+ $cb.add(key, value, args) # => if !quiet, Generates Couchbase::Error::KeyExists if key already exists
129
142
  end
130
143
 
131
144
  def replace_document(key, value, args = {})
132
145
  return nil unless key
133
- CB.quiet = args[:quiet] || true
134
- CB.replace(key, value) # => if !quiet, Generates Couchbase::Error::NotFound if key doesn't exist
146
+ $cb.quiet = args[:quiet] || true
147
+ $cb.replace(key, value) # => if !quiet, Generates Couchbase::Error::NotFound if key doesn't exist
135
148
  end
136
149
 
137
150
  def get_document(key, args = {})
138
151
  return nil unless key
139
- CB.quiet = args[:quiet] || true
140
- doc = CB.get(key, args)
152
+ $cb.quiet = args[:quiet] || true
153
+ doc = $cb.get(key, args)
141
154
  doc.is_a?(Hash) ? Map.new(doc) : doc
142
155
  end
143
156
 
144
157
  def get_documents(keys = [], args = {})
145
158
  return nil unless keys || keys.empty?
146
- values = CB.get(keys, args)
159
+ values = $cb.get(keys, args)
147
160
 
148
161
  if values.is_a? Hash
149
162
  tmp = []
@@ -160,27 +173,27 @@ module CouchbaseDocStore
160
173
 
161
174
  def delete_document(key, args={})
162
175
  return nil unless key
163
- CB.quiet = args[:quiet] || true
164
- CB.delete(key)
176
+ $cb.quiet = args[:quiet] || true
177
+ $cb.delete(key)
165
178
  end
166
179
 
167
180
  def increase_atomic_count(key, args={} )
168
181
  return nil unless key
169
- CB.quiet = args[:quiet] || true
170
- CB.incr(key, args[:amount] || 1)
182
+ $cb.quiet = args[:quiet] || true
183
+ $cb.incr(key, args[:amount] || 1)
171
184
  end
172
185
 
173
186
  def decrease_atomic_count(key, args={})
174
187
  return nil unless key
175
- CB.quiet = args[:quiet] || true
176
- CB.decr(key, args[:amount] || 1)
188
+ $cb.quiet = args[:quiet] || true
189
+ $cb.decr(key, args[:amount] || 1)
177
190
  end
178
191
 
179
192
  # preferred way is to use create/replace instead of this to make sure there are no collisions
180
193
  def force_set_document(key, value, args={})
181
194
  return nil unless key
182
- CB.quiet = args[:quiet] || true
183
- CB.set(key, value, args)
195
+ $cb.quiet = args[:quiet] || true
196
+ $cb.set(key, value, args)
184
197
  end
185
198
 
186
199
  end# end ClassMethods
@@ -0,0 +1,10 @@
1
+ require 'rails'
2
+ require 'couchbase-docstore'
3
+
4
+ module CouchbaseDocStore
5
+ class Railtie < Rails::Railtie
6
+ config.before_initialize do
7
+ CouchbaseDocStore.connect!
8
+ end
9
+ end
10
+ end
@@ -1,3 +1,3 @@
1
1
  module CouchbaseDocStore
2
- VERSION = "0.1.4"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: couchbase-docstore
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-24 00:00:00.000000000 Z
12
+ date: 2013-03-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: couchbase-settings
@@ -18,7 +18,7 @@ dependencies:
18
18
  requirements:
19
19
  - - ! '>='
20
20
  - !ruby/object:Gem::Version
21
- version: 0.1.0
21
+ version: 0.2.7
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
- version: 0.1.0
29
+ version: 0.2.7
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: couchbase
32
32
  requirement: !ruby/object:Gem::Requirement
@@ -34,7 +34,7 @@ dependencies:
34
34
  requirements:
35
35
  - - ! '>='
36
36
  - !ruby/object:Gem::Version
37
- version: 1.2.0.z.beta3
37
+ version: '1.2'
38
38
  type: :runtime
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
@@ -42,7 +42,7 @@ dependencies:
42
42
  requirements:
43
43
  - - ! '>='
44
44
  - !ruby/object:Gem::Version
45
- version: 1.2.0.z.beta3
45
+ version: '1.2'
46
46
  description: A Convenient Wrapper for the Couchbase gem, uses Map gem and adds new
47
47
  functionality
48
48
  email:
@@ -51,14 +51,14 @@ executables: []
51
51
  extensions: []
52
52
  extra_rdoc_files: []
53
53
  files:
54
- - .gitignore
55
54
  - Gemfile
56
55
  - LICENSE.txt
57
56
  - README.md
58
57
  - Rakefile
59
- - couchbase_doc_store.gemspec
60
- - lib/couchbase_doc_store.rb
58
+ - lib/couchbase-docstore.rb
59
+ - lib/couchbase_doc_store/railtie.rb
61
60
  - lib/couchbase_doc_store/version.rb
61
+ - couchbase-docstore.gemspec
62
62
  homepage: https://github.com/scalabl3/couchbase-docstore
63
63
  licenses: []
64
64
  post_install_message:
data/.gitignore DELETED
@@ -1,18 +0,0 @@
1
- go.sh
2
- *.gem
3
- *.rbc
4
- .bundle
5
- .config
6
- .yardoc
7
- Gemfile.lock
8
- InstalledFiles
9
- _yardoc
10
- coverage
11
- doc/
12
- lib/bundler/man
13
- pkg
14
- rdoc
15
- spec/reports
16
- test/tmp
17
- test/version_tmp
18
- tmp