relaxo 1.3.0 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 426efa86735d93046dbd4d55532954c7a99ea27e
4
- data.tar.gz: 26d8624fe4d3277e91fb2565d1c068b3a39ff121
2
+ SHA256:
3
+ metadata.gz: 9be2c95aada8b0d15d79f7376b32e57a07724cbe1fd93afa578091c0c522906c
4
+ data.tar.gz: b17fa3492dd504ba16a018fee637e8c1d3d293bdacc4fb84f65e5deefca3e792
5
5
  SHA512:
6
- metadata.gz: 0d504a18d7a283d7160ffb0a94d8e99bcbded19b3e408675c2d87a8dc582c28935b493cad5a1acd67d9ee984ef07243b55b8c636c6253d0dfbfdb981f26bab7b
7
- data.tar.gz: 4824e4933d9b090385e42c3a825ff01978fe132ccddf2efee1eb342dfab7df8682aafbf11f6ab416be89f1a5a34db4fbae55bd3021b5a94cd8d7e347d2d40606
6
+ metadata.gz: d0b4a7b024ad81169340891f1c7541bc2b5a1ecff678c4f4685b1aa8c7567546f6d0f7a69c078b132f6e9a88b90ea1d63ea14308c7984836850ac0ae1fe979d2
7
+ data.tar.gz: ded7e4a80713178e513f7b8d585e974fef763fb025d1d083f2574ecf553015cb519c059054ac4e61cae4ba33a30d0924b1f971ca2632cab08efa8e41a68562d7
@@ -23,15 +23,19 @@ require 'relaxo/database'
23
23
  require 'pry'
24
24
 
25
25
  module Relaxo
26
- def self.connect(path, metadata = {})
26
+ MASTER = 'master'.freeze
27
+
28
+ def self.connect(path, branch: nil, sync: nil, **metadata)
27
29
  unless File.exist?(path)
28
30
  repository = Rugged::Repository.init_at(path, true)
29
31
 
30
- if metadata[:sync] || ENV['RELAXO_SYNC']
32
+ if sync || ENV['RELAXO_SYNC']
31
33
  repository.config['core.fsyncObjectFiles'] = true
32
34
  end
33
35
  end
34
36
 
35
- return Database.new(path, metadata)
37
+ branch ||= MASTER
38
+
39
+ return Database.new(path, branch, metadata)
36
40
  end
37
41
  end
@@ -28,13 +28,15 @@ module Relaxo
28
28
  HEAD = 'HEAD'.freeze
29
29
 
30
30
  class Database
31
- def initialize(path, metadata = {})
31
+ def initialize(path, branch, metadata = {})
32
32
  @path = path
33
33
  @metadata = metadata
34
34
 
35
35
  @logger = metadata[:logger] || Logger.new($stderr).tap{|logger| logger.level = Logger::INFO}
36
36
 
37
37
  @repository = Rugged::Repository.new(path)
38
+
39
+ @branch = branch
38
40
  end
39
41
 
40
42
  attr :path
@@ -43,7 +45,9 @@ module Relaxo
43
45
 
44
46
  # Completely clear out the database.
45
47
  def clear!
46
- @repository.references.delete(@repository.head)
48
+ if head = @repository.branches[@branch]
49
+ @repository.references.delete(head)
50
+ end
47
51
  end
48
52
 
49
53
  def empty?
@@ -131,7 +135,7 @@ module Relaxo
131
135
 
132
136
  options[:tree] = changeset.write_tree
133
137
  options[:parents] ||= [parent]
134
- options[:update_ref] ||= HEAD
138
+ options[:update_ref] ||= "refs/heads/#{@branch}"
135
139
 
136
140
  begin
137
141
  Rugged::Commit.create(@repository, options)
@@ -141,13 +145,11 @@ module Relaxo
141
145
  end
142
146
 
143
147
  def latest_commit
144
- if head = @repository.head
148
+ if head = @repository.branches[@branch]
145
149
  return head.target, head.target.tree
146
150
  else
147
151
  return nil, empty_tree
148
152
  end
149
- rescue Rugged::ReferenceError
150
- return nil, empty_tree
151
153
  end
152
154
 
153
155
  def empty_tree
@@ -19,5 +19,5 @@
19
19
  # THE SOFTWARE.
20
20
 
21
21
  module Relaxo
22
- VERSION = "1.3.0"
22
+ VERSION = "1.4.0"
23
23
  end
@@ -15,6 +15,12 @@ RSpec.describe Relaxo::Database do
15
15
  expect(database).to be_empty
16
16
  end
17
17
 
18
+ it "can clear database" do
19
+ expect do
20
+ database.clear!
21
+ end.to_not raise_error
22
+ end
23
+
18
24
  it "should not be empty with one document" do
19
25
  database.commit(message: "Create test document") do |dataset|
20
26
  oid = dataset.append(sample_json)
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: 1.3.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-12 00:00:00.000000000 Z
11
+ date: 2018-06-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rugged
@@ -90,7 +90,6 @@ files:
90
90
  - lib/relaxo/database.rb
91
91
  - lib/relaxo/dataset.rb
92
92
  - lib/relaxo/directory.rb
93
- - lib/relaxo/schema.rb
94
93
  - lib/relaxo/version.rb
95
94
  - relaxo.gemspec
96
95
  - spec/relaxo/changeset_spec.rb
@@ -120,7 +119,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
120
119
  version: '0'
121
120
  requirements: []
122
121
  rubyforge_project:
123
- rubygems_version: 2.6.12
122
+ rubygems_version: 2.7.6
124
123
  signing_key:
125
124
  specification_version: 4
126
125
  summary: Relaxo is a helper for loading and working with CouchDB.
@@ -1,49 +0,0 @@
1
- # Copyright, 2016, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the "Software"), to deal
5
- # in the Software without restriction, including without limitation the rights
6
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- # copies of the Software, and to permit persons to whom the Software is
8
- # furnished to do so, subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in
11
- # all copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- # THE SOFTWARE.
20
-
21
- require 'yaml'
22
-
23
- module Relaxo
24
- class Schema
25
- def initialize(document)
26
- @document = document
27
- end
28
-
29
- def self.load_file(schema_path)
30
- self.new(YAML.load_file(schema_path))
31
- end
32
-
33
- def id
34
- @document[ID]
35
- end
36
-
37
- def migrate(db)
38
- if db.id?(self.id)
39
- if existing_document = GeoZone::DB.get(self.id)
40
- @document[Relaxo::REV] = existing_document[Relaxo::REV]
41
- end
42
- end
43
-
44
- if existing_document != @document
45
- db.save(@document)
46
- end
47
- end
48
- end
49
- end