relaxo 0.4.4 → 0.4.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 64d93992b8989b3da2ea1d3538d65bec9803a556
4
- data.tar.gz: e559ca748c9c1b13acf35980fa31d8152a2a456d
3
+ metadata.gz: 0f271109f32a46b527537f02d2d74d11c0b6bec8
4
+ data.tar.gz: f420d81ae8aefaa83d76aeff87e14ce1a3bf4041
5
5
  SHA512:
6
- metadata.gz: efd8db9bc3dc670ff3db9f44a517bb2c64a786b9a07363bcb2f232c49060fef0b1b393d8e37437a3cbc7f554238486e1dd9ef0a2945a0942965c60308b1e2ddd
7
- data.tar.gz: 7d37db1c92596301d4ef68121b05cd162c20fb2d9ab6fe46a93117f3b7a79fa6e0ca1bcc70c0649a80d4f2cbb3a6c4f5159126f6b95455a2c23d535ad96f947e
6
+ metadata.gz: 0303b6aa8c28daca4eab2de9485fd0fead7a9ae2272d2c10c936d3ce15481344555cc2744b1bae5221dea1955e8b253a77832a5f1e838d597837e3b10ffdf727
7
+ data.tar.gz: 96314b1bbc9dd5fb2b9a036c1b7e37da3dac2ad9516c1d9fa91ad88179f1095b8740270a0513f5dee371dcfa40cef9dc7dd587fe73b5b0621fc2f1404d31b1db
@@ -1,11 +1,8 @@
1
1
  language: ruby
2
2
  rvm:
3
- - "1.8.7"
4
- - "1.9.2"
5
- - "1.9.3"
6
- - jruby-18mode # JRuby in 1.8 mode
7
- - jruby-19mode # JRuby in 1.9 mode
8
- - rbx-18mode
9
- - rbx-19mode
3
+ - 2.0
4
+ - 2.1
5
+ - 2.2
10
6
  services:
11
7
  - couchdb
8
+ env: COVERAGE=true
data/Gemfile CHANGED
@@ -4,5 +4,10 @@ source 'https://rubygems.org'
4
4
  gemspec
5
5
 
6
6
  platforms :jruby do
7
- gem 'jruby-openssl'
7
+ gem 'jruby-openssl'
8
+ end
9
+
10
+ group :test do
11
+ gem 'simplecov'
12
+ gem 'coveralls', require: false
8
13
  end
@@ -21,7 +21,7 @@
21
21
  require 'relaxo/database'
22
22
 
23
23
  module Relaxo
24
- def self.connect(url)
24
+ def self.connect(url, metadata = nil)
25
25
  host = "http://localhost:5984"
26
26
 
27
27
  if url =~ /^(https?:\/\/.+?)\/(.+)$/
@@ -37,6 +37,6 @@ module Relaxo
37
37
  end
38
38
 
39
39
  connection = Connection.new(host)
40
- database = Database.new(connection, name)
40
+ database = Database.new(connection, name, metadata)
41
41
  end
42
42
  end
@@ -20,6 +20,8 @@
20
20
 
21
21
  require 'relaxo/client'
22
22
 
23
+ require 'thread'
24
+
23
25
  module Relaxo
24
26
  class Connection
25
27
  DEFAULT_UUID_FETCH_COUNT = 10
@@ -27,18 +29,23 @@ module Relaxo
27
29
  def initialize(url)
28
30
  @url = url
29
31
  @uuids = []
32
+
33
+ @uuid_lock = Mutex.new
30
34
  end
31
35
 
32
36
  attr :url
33
37
 
34
- def fetch_uuids(count)
38
+ private def fetch_uuids(count)
35
39
  @uuids += Client.get("#{@url}/_uuids?count=#{count}")["uuids"]
36
40
  end
37
41
 
42
+ # This implementation could be improved. It's not exactly fast to request 1 UUID at a time. One idea is to add a UUID queue to Transaction which allows UUIDs to be fetched in bulk on a per-transaction basis, and reused if the transaction fails.
38
43
  def next_uuid
39
- fetch_uuids(DEFAULT_UUID_FETCH_COUNT) if @uuids.size == 0
44
+ @uuid_lock.synchronize do
45
+ fetch_uuids(DEFAULT_UUID_FETCH_COUNT) if @uuids.size == 0
40
46
 
41
- @uuids.pop
47
+ return @uuids.pop
48
+ end
42
49
  end
43
50
 
44
51
  def info
@@ -49,5 +56,9 @@ module Relaxo
49
56
  def databases
50
57
  Client.get("#{@url}/_all_dbs")
51
58
  end
59
+
60
+ def configuration
61
+ Client.get("#{@url}/_config")
62
+ end
52
63
  end
53
64
  end
@@ -27,10 +27,12 @@ module Relaxo
27
27
  DELETED = '_deleted'
28
28
 
29
29
  class Database
30
- def initialize(connection, name)
30
+ def initialize(connection, name, metadata = {})
31
31
  @connection = connection
32
32
  @name = name
33
33
 
34
+ @metadata = metadata
35
+
34
36
  @root = connection.url + "/" + CGI.escape(name)
35
37
  end
36
38
 
@@ -38,6 +40,12 @@ module Relaxo
38
40
  attr :name
39
41
  attr :root
40
42
 
43
+ attr :metadata
44
+
45
+ def [] key
46
+ @metadata[key]
47
+ end
48
+
41
49
  # Create the database, will potentially throw an exception if it already exists.
42
50
  def create!
43
51
  Client.put @root
@@ -25,8 +25,8 @@ module Relaxo
25
25
 
26
26
  # We monkey-patch this in as Transaction is basically an optional feature for doing bulk_saves.
27
27
  class Database
28
- def transaction(klass = nil)
29
- transaction = Transaction.new(self)
28
+ def transaction(klass = nil, metadata = {})
29
+ transaction = Transaction.new(self, metadata)
30
30
 
31
31
  catch(:abort) do
32
32
  yield transaction
@@ -43,13 +43,18 @@ module Relaxo
43
43
  end
44
44
 
45
45
  class Transaction
46
- def initialize(database)
46
+ def initialize(database, metadata = {})
47
47
  @database = database
48
+ @metadata = {}
48
49
 
49
50
  @documents = []
50
51
  @uuids = []
51
52
  end
52
53
 
54
+ def [] key
55
+ @metadata[key] || @database[key]
56
+ end
57
+
53
58
  def get(*args)
54
59
  @database.get(*args)
55
60
  end
@@ -19,5 +19,5 @@
19
19
  # THE SOFTWARE.
20
20
 
21
21
  module Relaxo
22
- VERSION = "0.4.4"
22
+ VERSION = "0.4.5"
23
23
  end
@@ -25,7 +25,7 @@ Gem::Specification.new do |spec|
25
25
  spec.add_dependency "json", "~> 1.8"
26
26
  spec.add_dependency "rest-client"
27
27
 
28
- spec.add_development_dependency "rspec", "~> 3.1.0"
28
+ spec.add_development_dependency "rspec", "~> 3.4.0"
29
29
  spec.add_development_dependency "bundler", "~> 1.3"
30
30
  spec.add_development_dependency "rake"
31
31
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: relaxo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.4
4
+ version: 0.4.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-08 00:00:00.000000000 Z
11
+ date: 2016-05-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 3.1.0
47
+ version: 3.4.0
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 3.1.0
54
+ version: 3.4.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: bundler
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -132,7 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
132
132
  version: '0'
133
133
  requirements: []
134
134
  rubyforge_project:
135
- rubygems_version: 2.2.2
135
+ rubygems_version: 2.5.1
136
136
  signing_key:
137
137
  specification_version: 4
138
138
  summary: Relaxo is a helper for loading and working with CouchDB.