couchbase 1.1.0-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,113 @@
1
+ # encoding: UTF-8
2
+ # Author:: Couchbase <info@couchbase.com>
3
+ # Copyright:: 2011, 2012 Couchbase, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ ENV['RC_ARCHS'] = '' if RUBY_PLATFORM =~ /darwin/
20
+
21
+ require 'mkmf'
22
+
23
+ def define(macro, value = nil)
24
+ $defs.push("-D #{[macro.upcase, value].compact.join('=')}")
25
+ end
26
+
27
+ $CFLAGS << " #{ENV["CFLAGS"]}"
28
+ $LDFLAGS << " #{ENV["LDFLAGS"]}"
29
+ $LIBS << " #{ENV["LIBS"]}"
30
+
31
+ $CFLAGS << ' -std=c99 -Wall -Wextra '
32
+ if ENV['DEBUG']
33
+ $CFLAGS << ' -O0 -ggdb3 -pedantic '
34
+ end
35
+
36
+ if RbConfig::CONFIG['target_os'] =~ /mingw32/
37
+ dir_config("libcouchbase")
38
+ else
39
+ LIBDIR = RbConfig::CONFIG['libdir']
40
+ INCLUDEDIR = RbConfig::CONFIG['includedir']
41
+
42
+ HEADER_DIRS = [
43
+ # First search /opt/local for macports
44
+ '/opt/local/include',
45
+ # Then search /usr/local for people that installed from source
46
+ '/usr/local/include',
47
+ # Check the ruby install locations
48
+ INCLUDEDIR,
49
+ # Finally fall back to /usr
50
+ '/usr/include'
51
+ ]
52
+
53
+ LIB_DIRS = [
54
+ # First search /opt/local for macports
55
+ '/opt/local/lib',
56
+ # Then search /usr/local for people that installed from source
57
+ '/usr/local/lib',
58
+ # Check the ruby install locations
59
+ LIBDIR,
60
+ # Finally fall back to /usr
61
+ '/usr/lib'
62
+ ]
63
+
64
+ # For people using homebrew
65
+ brew_prefix = `brew --prefix libevent 2> /dev/null`.chomp
66
+ unless brew_prefix.empty?
67
+ LIB_DIRS.unshift File.join(brew_prefix, 'lib')
68
+ HEADER_DIRS.unshift File.join(brew_prefix, 'include')
69
+ end
70
+
71
+ HEADER_DIRS.delete_if{|d| !File.exists?(d)}
72
+ LIB_DIRS.delete_if{|d| !File.exists?(d)}
73
+
74
+ # it will find the libcouchbase likely. you can specify its path otherwise
75
+ #
76
+ # ruby extconf.rb [--with-libcouchbase-include=<dir>] [--with-libcouchbase-lib=<dir>]
77
+ #
78
+ # or
79
+ #
80
+ # ruby extconf.rb [--with-libcouchbase-dir=<dir>]
81
+ #
82
+ dir_config("libcouchbase", HEADER_DIRS, LIB_DIRS)
83
+ end
84
+
85
+ if COMMON_HEADERS !~ /"ruby\.h"/
86
+ COMMON_HEADERS << %(\n#include "ruby.h"\n)
87
+ end
88
+
89
+ if try_compile(<<-SRC)
90
+ #include <stdarg.h>
91
+ int foo(int x, ...) {
92
+ va_list va;
93
+ va_start(va, x);
94
+ va_arg(va, int);
95
+ va_arg(va, char *);
96
+ va_arg(va, double);
97
+ return 0;
98
+ }
99
+ int main() {
100
+ return foo(10, "", 3.14);
101
+ return 0;
102
+ }
103
+ SRC
104
+ define("HAVE_STDARG_PROTOTYPES")
105
+ end
106
+
107
+
108
+ if RbConfig::CONFIG['target_os'] =~ /mingw32/
109
+ have_library("vbucket", "vbucket_config_create", "libvbucket/vbucket.h") or abort "You should install libvbucket >= 1.8.0.2"
110
+ end
111
+ have_library("couchbase", "libcouchbase_server_versions", "libcouchbase/couchbase.h") or abort "You should install libcouchbase >= 1.0.2"
112
+ create_header("couchbase_config.h")
113
+ create_makefile("couchbase_ext")
data/lib/couchbase.rb ADDED
@@ -0,0 +1,81 @@
1
+ # Author:: Couchbase <info@couchbase.com>
2
+ # Copyright:: 2011, 2012 Couchbase, Inc.
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+ require 'couchbase/version'
19
+ require 'yajl/json_gem'
20
+ require 'uri'
21
+ require 'couchbase_ext'
22
+ require 'couchbase/bucket'
23
+
24
+ # Couchbase ruby client
25
+ module Couchbase
26
+
27
+ class << self
28
+ # The method +connect+ initializes new Bucket instance with all arguments passed.
29
+ #
30
+ # @example Use default values for all options
31
+ # Couchbase.connect
32
+ #
33
+ # @example Establish connection with couchbase default pool and default bucket
34
+ # Couchbase.connect("http://localhost:8091/pools/default")
35
+ #
36
+ # @example Select custom bucket
37
+ # Couchbase.connect("http://localhost:8091/pools/default", :bucket => 'blog')
38
+ #
39
+ # @example Specify bucket credentials
40
+ # Couchbase.connect("http://localhost:8091/pools/default", :bucket => 'blog', :username => 'bucket', :password => 'secret')
41
+ #
42
+ # @return [Bucket] connection instance
43
+ def connect(*options)
44
+ Bucket.new(*options)
45
+ end
46
+ alias :new :connect
47
+
48
+ # Default connection options
49
+ #
50
+ # @example Using {Couchbase#connection_options} to change the bucket
51
+ # Couchbase.connection_options = {:bucket => 'blog'}
52
+ # Couchbase.bucket.name #=> "blog"
53
+ #
54
+ # @return [Hash, String]
55
+ attr_accessor :connection_options
56
+
57
+ # @private the thread local storage
58
+ def thread_storage
59
+ Thread.current[:couchbase] ||= {}
60
+ end
61
+
62
+ # The connection instance for current thread
63
+ #
64
+ # @example
65
+ # Couchbase.bucket.set("foo", "bar")
66
+ #
67
+ # @return [Bucket]
68
+ def bucket
69
+ thread_storage[:bucket] ||= connect(*connection_options)
70
+ end
71
+
72
+ # Set a connection instance for current thread
73
+ #
74
+ # @return [Bucket]
75
+ def bucket=(connection)
76
+ thread_storage[:bucket] = connection
77
+ end
78
+
79
+ end
80
+
81
+ end
@@ -0,0 +1,72 @@
1
+ # Author:: Couchbase <info@couchbase.com>
2
+ # Copyright:: 2011, 2012 Couchbase, Inc.
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+ module Couchbase
19
+
20
+ class Bucket
21
+
22
+ # Reads a key's value from the server and yields it to a block. Replaces
23
+ # the key's value with the result of the block as long as the key hasn't
24
+ # been updated in the meantime, otherwise raises
25
+ # {Couchbase::Error::KeyExists}. CAS stands for "compare and swap", and
26
+ # avoids the need for manual key mutexing. Read more info here:
27
+ #
28
+ # http://docs.couchbase.org/memcached-api/memcached-api-protocol-text_cas.html
29
+ #
30
+ # @param [String, Symbol] key
31
+ #
32
+ # @param [Hash] options the options for operation
33
+ # @option options [String] :ttl (self.default_ttl) the time to live of this key
34
+ # @option options [Symbol] :format (self.default_format) format of the value
35
+ # @option options [Fixnum] :flags (self.default_flags) flags for this key
36
+ #
37
+ # @yieldparam [Object, Result] value old value in synchronous mode and
38
+ # +Result+ object in asynchronous mode.
39
+ # @yieldreturn [Object] new value.
40
+ #
41
+ # @raise [Couchbase::Error::KeyExists] if the key was updated before the the
42
+ # code in block has been completed (the CAS value has been changed).
43
+ #
44
+ # @example Implement append to JSON encoded value
45
+ #
46
+ # c.default_format = :document
47
+ # c.set("foo", {"bar" => 1})
48
+ # c.cas("foo") do |val|
49
+ # val["baz"] = 2
50
+ # val
51
+ # end
52
+ # c.get("foo") #=> {"bar" => 1, "baz" => 2}
53
+ #
54
+ # @return [Fixnum] the CAS of new value
55
+ def cas(key, options = {})
56
+ options = options.merge(:extended => true)
57
+ if async?
58
+ get(key, options) do |ret|
59
+ val = yield(ret) # get new value from caller
60
+ set(ret.key, val, :cas => ret.cas)
61
+ end
62
+ else
63
+ val, flags, ver = get(key, options)
64
+ val = yield(val) # get new value from caller
65
+ set(key, val, :cas => ver)
66
+ end
67
+ end
68
+ alias :compare_and_swap :cas
69
+
70
+ end
71
+
72
+ end
@@ -0,0 +1,21 @@
1
+ # Author:: Couchbase <info@couchbase.com>
2
+ # Copyright:: 2011, 2012 Couchbase, Inc.
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+ # Couchbase ruby client
19
+ module Couchbase
20
+ VERSION = "1.1.0"
21
+ end
@@ -0,0 +1,6 @@
1
+ desc 'Run benchmarks and compare them to memcached and dalli gems'
2
+ task :benchmark => [:clean, :compile] do
3
+ cd File.expand_path(File.join(__FILE__, '..', '..', 'test', 'profile')) do
4
+ sh "bundle install && bundle exec ruby benchmark.rb | tee benchmark-#{RUBY_VERSION}p#{RUBY_PATCHLEVEL}.log"
5
+ end
6
+ end
@@ -0,0 +1,124 @@
1
+ # Author:: Couchbase <info@couchbase.com>
2
+ # Copyright:: 2011, 2012 Couchbase, Inc.
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+ gem 'rake-compiler', '>= 0.7.5'
19
+ require "rake/extensiontask"
20
+
21
+ def gemspec
22
+ @clean_gemspec ||= eval(File.read(File.expand_path('../../couchbase.gemspec', __FILE__)))
23
+ end
24
+
25
+ # Setup compile tasks. Configuration can be passed via ENV.
26
+ # Example:
27
+ # rake compile with_libcouchbase_include=/opt/couchbase/include
28
+ # with_libcouchbase_lib=/opt/couchbase/lib
29
+ #
30
+ # or
31
+ #
32
+ # rake compile with_libcouchbase_dir=/opt/couchbase
33
+ #
34
+ Rake::ExtensionTask.new("couchbase_ext", gemspec) do |ext|
35
+ ext.cross_compile = true
36
+ ext.cross_platform = [ENV['HOST'] || "i386-mingw32"]
37
+ if ENV['RUBY_CC_VERSION']
38
+ ext.lib_dir = "lib/couchbase"
39
+ end
40
+ ext.cross_compiling do |spec|
41
+ spec.files.delete("lib/couchbase/couchbase_ext.so")
42
+ spec.files.push("lib/couchbase_ext.rb", Dir["lib/couchbase/1.{8,9}/couchbase_ext.so"])
43
+ end
44
+
45
+ CLEAN.include "#{ext.lib_dir}/*.#{RbConfig::CONFIG['DLEXT']}"
46
+
47
+ ENV.each do |key, val|
48
+ next unless key =~ /\Awith_(\w+)\z/i
49
+ opt = $1.downcase.tr('_', '-')
50
+ if File.directory?(path = File.expand_path(val))
51
+ ext.config_options << "--with-#{opt}=#{path}"
52
+ else
53
+ warn "No such directory: #{opt}: #{path}"
54
+ end
55
+ end
56
+ end
57
+
58
+ require 'rubygems/package_task'
59
+ Gem::PackageTask.new(gemspec) do |pkg|
60
+ pkg.need_zip = true
61
+ pkg.need_tar = true
62
+ end
63
+
64
+ require 'mini_portile'
65
+ require 'rake/extensioncompiler'
66
+
67
+ class MiniPortile
68
+ alias :initialize_with_default_host :initialize
69
+ def initialize(name, version)
70
+ initialize_with_default_host(name, version)
71
+ @host = ENV['HOST'] || Rake::ExtensionCompiler.mingw_host
72
+ end
73
+
74
+ alias :cook_without_checkpoint :cook
75
+ def cook
76
+ checkpoint = "ports/.#{name}-#{version}-#{host}.installed"
77
+ unless File.exist?(checkpoint)
78
+ cook_without_checkpoint
79
+ FileUtils.touch(checkpoint)
80
+ end
81
+ end
82
+ end
83
+
84
+ namespace :ports do
85
+ directory "ports"
86
+
87
+ task :libvbucket => ["ports"] do
88
+ recipe = MiniPortile.new "libvbucket", "1.8.0.3"
89
+ recipe.files << "http://packages.couchbase.com/clients/c/#{recipe.name}-#{recipe.version}.tar.gz"
90
+ recipe.configure_options.push("--disable-debug",
91
+ "--without-docs",
92
+ "--disable-dependency-tracking")
93
+ recipe.cook
94
+ recipe.activate
95
+ end
96
+
97
+ task :libcouchbase => [:libvbucket] do
98
+ recipe = MiniPortile.new "libcouchbase", "1.0.2"
99
+ recipe.files << "http://packages.couchbase.com/clients/c/#{recipe.name}-#{recipe.version}.tar.gz"
100
+ recipe.configure_options.push("--disable-debug",
101
+ "--disable-dependency-tracking",
102
+ "--disable-couchbasemock",
103
+ "--disable-tools")
104
+ recipe.cook
105
+ recipe.activate
106
+ end
107
+ end
108
+
109
+ file "lib/couchbase_ext.rb" do
110
+ File.open("lib/couchbase_ext.rb", 'wb') do |f|
111
+ f.write <<-RUBY
112
+ require "couchbase/\#{RUBY_VERSION.sub(/\\.\\d+$/, '')}/couchbase_ext"
113
+ RUBY
114
+ end
115
+ end
116
+
117
+ task :cross => ["lib/couchbase_ext.rb", "ports:libcouchbase"]
118
+
119
+ desc "Package gem for windows"
120
+ task "package:windows" => :package do
121
+ sh("env RUBY_CC_VERSION=1.8.7 rvm 1.8.7 do bundle exec rake cross compile")
122
+ sh("env RUBY_CC_VERSION=1.9.2 rvm 1.9.2 do bundle exec rake cross compile")
123
+ sh("env RUBY_CC_VERSION=1.8.7:1.9.2 rvm 1.9.2 do bundle exec rake cross native gem")
124
+ end
data/tasks/doc.rake ADDED
@@ -0,0 +1,27 @@
1
+ # Author:: Couchbase <info@couchbase.com>
2
+ # Copyright:: 2011, 2012 Couchbase, Inc.
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+ require 'rake/clean'
19
+ require 'yard'
20
+ require 'yard/rake/yardoc_task'
21
+
22
+ YARD::Rake::YardocTask.new do |t|
23
+ t.options = %w(--protected --no-private)
24
+ t.files.push('-', 'README.markdown', 'HISTORY.markdown')
25
+ end
26
+
27
+ #CLOBBER << 'test/CouchbaseMock.jar'