relaxo 1.0.1 → 1.2.0

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: 801d2413ec4ce9a0befc4ad46726900c09453cb8
4
- data.tar.gz: e9b179cd2f9a6da4083848c3197f69b328dc455e
3
+ metadata.gz: 0001153bcb2843832dc1f6ad29e49885db98729d
4
+ data.tar.gz: 0e065a359e1ae3f0ff21ecc1848b2189f3f5345e
5
5
  SHA512:
6
- metadata.gz: 6f5c211fdb870371d30dd6555b556771a78a12408004db4bc1be125bcced2daa64bf05c989a8a8045b0456a64cc277d9fc1d132af9f26ed6a76c7ede4c3714af
7
- data.tar.gz: 9f6a3c721c120a000666fb192fc2d779ff62a3d0ab714cc24f75284bfa6ca1bfe72cd5e32be469c241af28a43b6a3309f683dda823a76ecd74dd638eba176c68
6
+ metadata.gz: 768562aeadc873bdd50df1a49ef3a455f64d9a6bc56d2edb4fcf5fe0876e46b6a83f137a677df3faac8cac46aa3da8dc4b6eff91157fc152f0478e621e93922b
7
+ data.tar.gz: f88b84ef0e018606ef3696688755315d6fd0092fb201de2e76186b5cd1606b8162f72cadf32650dad2513767850e36eadd8af7028722b74aef5ae4d5c9c98ec4
data/.rspec CHANGED
@@ -1,3 +1,4 @@
1
- --color
2
- --format documentation
1
+ --format documentation
2
+ --backtrace
3
3
  --warnings
4
+ --require spec_helper
@@ -1,17 +1,15 @@
1
1
  language: ruby
2
2
  sudo: false
3
- before_install:
4
- # For testing purposes:
5
- - git config --global user.name "Samuel Williams"
6
- - git config --global user.email "samuel@oriontransfer.net"
3
+ dist: trusty
4
+ cache: bundler
7
5
  rvm:
8
- - 2.1.8
9
- - 2.2.4
10
- - 2.3.1
11
- - 2.4.0
12
- - rbx-2
13
- env: COVERAGE=true BENCHMARK=true
6
+ - 2.1
7
+ - 2.2
8
+ - 2.3
9
+ - 2.4
10
+ - ruby-head
11
+ - jruby-head
14
12
  matrix:
15
13
  allow_failures:
16
- - rvm: ruby-head
17
- - rvm: "rbx-2"
14
+ - rvm: "ruby-head"
15
+ - rvm: "jruby-head"
data/Gemfile CHANGED
@@ -3,7 +3,7 @@ source 'https://rubygems.org'
3
3
  # Specify your gem's dependencies in relaxo.gemspec
4
4
  gemspec
5
5
 
6
- gem 'rugged', git: 'git://github.com/libgit2/rugged.git', submodules: true
6
+ gem 'rugged', git: 'https://github.com/libgit2/rugged.git', submodules: true
7
7
 
8
8
  group :development do
9
9
  gem "pry"
@@ -25,7 +25,11 @@ require 'pry'
25
25
  module Relaxo
26
26
  def self.connect(path, metadata = {})
27
27
  unless File.exist?(path)
28
- Rugged::Repository.init_at(path, true)
28
+ repository = Rugged::Repository.init_at(path, true)
29
+
30
+ if metadata[:sync] || ENV['RELAXO_SYNC']
31
+ repository.config['core.fsyncObjectFiles'] = true
32
+ end
29
33
  end
30
34
 
31
35
  return Database.new(path, metadata)
@@ -65,7 +65,7 @@ module Relaxo
65
65
  name: name,
66
66
  }
67
67
 
68
- directory(root).insert(entry)
68
+ fetch_directory(root).insert(entry)
69
69
 
70
70
  return entry
71
71
  end
@@ -82,7 +82,7 @@ module Relaxo
82
82
  name: name,
83
83
  }
84
84
 
85
- directory(root).delete(entry)
85
+ fetch_directory(root).delete(entry)
86
86
 
87
87
  return entry
88
88
  end
@@ -34,7 +34,7 @@ module Relaxo
34
34
 
35
35
  @logger = metadata[:logger] || Logger.new($stderr).tap{|logger| logger.level = Logger::INFO}
36
36
 
37
- @repository = repository || Rugged::Repository.new(path)
37
+ @repository = Rugged::Repository.new(path)
38
38
  end
39
39
 
40
40
  attr :path
@@ -41,19 +41,31 @@ module Relaxo
41
41
 
42
42
  alias [] read
43
43
 
44
+ def file?
45
+ read(path)
46
+ end
47
+
44
48
  def exist?(path)
45
- read(path) != nil
49
+ read(path) or directory?(path)
50
+ end
51
+
52
+ def directory?(path)
53
+ @directories.key?(path) or @tree.path(path)[:type] == :tree
54
+ rescue Rugged::TreeError
55
+ return false
46
56
  end
47
57
 
48
- def each(path = nil, &block)
58
+ def each(path = '', &block)
49
59
  return to_enum(:each, path) unless block_given?
50
60
 
51
- directory(path).each(&block)
61
+ directory = fetch_directory(path)
62
+
63
+ directory.each(&block)
52
64
  end
53
65
 
54
66
  protected
55
67
 
56
- def directory(path = nil)
68
+ def fetch_directory(path)
57
69
  @directories[path] ||= Directory.new(@repository, @tree, path)
58
70
  end
59
71
  end
@@ -22,9 +22,16 @@ require 'rugged'
22
22
 
23
23
  module Relaxo
24
24
  class Directory
25
- def initialize(repository, tree, path)
25
+ def initialize(repository, root_tree, path)
26
26
  @repository = repository
27
- @tree = tree
27
+
28
+ # The root tree, which path is relative to:
29
+ @root_tree = root_tree
30
+
31
+ # The entry and tree for the directory itself:
32
+ @entry = nil
33
+ @tree = nil
34
+
28
35
  @path = path
29
36
 
30
37
  @entries = nil
@@ -51,6 +58,12 @@ module Relaxo
51
58
  end
52
59
  end
53
60
 
61
+ def each_entry(&block)
62
+ return to_enum(:each_entry) unless block_given?
63
+
64
+ entries.each(&block)
65
+ end
66
+
54
67
  def insert(entry)
55
68
  _, _, name = entry[:name].rpartition('/')
56
69
 
@@ -71,10 +84,14 @@ module Relaxo
71
84
 
72
85
  private
73
86
 
74
- def fetch_tree(path = @path)
75
- entry = @tree.path(path)
76
-
77
- Rugged::Tree.new(@repository, entry[:oid])
87
+ # Look up the entry for the given directory `@path`:
88
+ def fetch_entry
89
+ @entry ||= @root_tree.path(@path)
90
+ end
91
+
92
+ # Load the directory tree for the given `@path`:
93
+ def fetch_tree
94
+ @tree ||= Rugged::Tree.new(@repository, fetch_entry[:oid])
78
95
  rescue Rugged::TreeError
79
96
  return nil
80
97
  end
@@ -19,5 +19,5 @@
19
19
  # THE SOFTWARE.
20
20
 
21
21
  module Relaxo
22
- VERSION = "1.0.1"
22
+ VERSION = "1.2.0"
23
23
  end
@@ -24,7 +24,7 @@ Gem::Specification.new do |spec|
24
24
 
25
25
  spec.add_dependency "rugged"
26
26
 
27
- spec.add_development_dependency "rspec", "~> 3.4.0"
27
+ spec.add_development_dependency "rspec", "~> 3.6"
28
28
  spec.add_development_dependency "bundler", "~> 1.3"
29
29
  spec.add_development_dependency "rake"
30
30
  end
@@ -0,0 +1,29 @@
1
+
2
+ if ENV['COVERAGE'] || ENV['TRAVIS']
3
+ begin
4
+ require 'simplecov'
5
+
6
+ SimpleCov.start do
7
+ add_filter "/spec/"
8
+ end
9
+
10
+ if ENV['TRAVIS']
11
+ require 'coveralls'
12
+ Coveralls.wear!
13
+ end
14
+ rescue LoadError
15
+ warn "Could not load simplecov: #{$!}"
16
+ end
17
+ end
18
+
19
+ require "bundler/setup"
20
+ require "relaxo"
21
+
22
+ RSpec.configure do |config|
23
+ # Enable flags like --only-failures and --next-failure
24
+ config.example_status_persistence_file_path = ".rspec_status"
25
+
26
+ config.expect_with :rspec do |c|
27
+ c.syntax = :expect
28
+ end
29
+ 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: 1.0.1
4
+ version: 1.2.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: 2017-05-13 00:00:00.000000000 Z
11
+ date: 2017-08-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rugged
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 3.4.0
33
+ version: '3.6'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 3.4.0
40
+ version: '3.6'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -79,7 +79,6 @@ extra_rdoc_files: []
79
79
  files:
80
80
  - ".gitignore"
81
81
  - ".rspec"
82
- - ".simplecov"
83
82
  - ".travis.yml"
84
83
  - Gemfile
85
84
  - README.md
@@ -100,6 +99,7 @@ files:
100
99
  - spec/relaxo/enumeration_spec.rb
101
100
  - spec/relaxo/performance_spec.rb
102
101
  - spec/relaxo/test_records.rb
102
+ - spec/spec_helper.rb
103
103
  homepage: ''
104
104
  licenses:
105
105
  - MIT
@@ -120,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
120
120
  version: '0'
121
121
  requirements: []
122
122
  rubyforge_project:
123
- rubygems_version: 2.6.10
123
+ rubygems_version: 2.6.12
124
124
  signing_key:
125
125
  specification_version: 4
126
126
  summary: Relaxo is a helper for loading and working with CouchDB.
@@ -131,3 +131,4 @@ test_files:
131
131
  - spec/relaxo/enumeration_spec.rb
132
132
  - spec/relaxo/performance_spec.rb
133
133
  - spec/relaxo/test_records.rb
134
+ - spec/spec_helper.rb
data/.simplecov DELETED
@@ -1,9 +0,0 @@
1
-
2
- SimpleCov.start do
3
- add_filter "/spec/"
4
- end
5
-
6
- if ENV['TRAVIS']
7
- require 'coveralls'
8
- Coveralls.wear!
9
- end