relaxo 1.0.1 → 1.6.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: 801d2413ec4ce9a0befc4ad46726900c09453cb8
4
- data.tar.gz: e9b179cd2f9a6da4083848c3197f69b328dc455e
2
+ SHA256:
3
+ metadata.gz: ae1194ada958c694f278dd6340b8c910bf79e79f66735fb5e1f8c6acc7e8417a
4
+ data.tar.gz: fee89902ec4e5dc0a77c0642b47cc997d13a90f30f7ad51bf008f765aeccdeef
5
5
  SHA512:
6
- metadata.gz: 6f5c211fdb870371d30dd6555b556771a78a12408004db4bc1be125bcced2daa64bf05c989a8a8045b0456a64cc277d9fc1d132af9f26ed6a76c7ede4c3714af
7
- data.tar.gz: 9f6a3c721c120a000666fb192fc2d779ff62a3d0ab714cc24f75284bfa6ca1bfe72cd5e32be469c241af28a43b6a3309f683dda823a76ecd74dd638eba176c68
6
+ metadata.gz: 8280b8de30982f10ac8753cf49a3e4e2149b82b387037a8038173f9f1c29e6aa1e61d417fb22789615db5b8907c16da25194c8073cf3e5e811ecb2b8764bb441
7
+ data.tar.gz: ed739652d8c5b8cd5e04b10f122faa426af7a8f9e7bf7d0e90643664c7677f52e96444e257b1611830e291de95fd2eb8395d5c4931546f8a8824c9fbd0af064f
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2012 Samuel G. D. Williams. <http://www.oriontransfer.co.nz>
1
+ # Copyright, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
2
  #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  # of this software and associated documentation files (the "Software"), to deal
@@ -20,14 +20,35 @@
20
20
 
21
21
  require 'relaxo/database'
22
22
 
23
- require 'pry'
23
+ require 'etc'
24
+ require 'socket'
24
25
 
25
26
  module Relaxo
26
- def self.connect(path, metadata = {})
27
+ MASTER = 'master'.freeze
28
+
29
+ def self.connect(path, branch: nil, sync: nil, **metadata)
27
30
  unless File.exist?(path)
28
- Rugged::Repository.init_at(path, true)
31
+ repository = Rugged::Repository.init_at(path, true)
32
+
33
+ if sync || ENV['RELAXO_SYNC']
34
+ repository.config['core.fsyncObjectFiles'] = true
35
+ end
29
36
  end
30
37
 
31
- return Database.new(path, metadata)
38
+ branch ||= MASTER
39
+
40
+ database = Database.new(path, branch, metadata)
41
+
42
+ if config = database.config
43
+ unless config['user.name']
44
+ login = Etc.getlogin
45
+ hostname = Socket.gethostname
46
+
47
+ config['user.name'] = login
48
+ config['user.email'] = "#{login}@#{hostname}"
49
+ end
50
+ end
51
+
52
+ return database
32
53
  end
33
54
  end
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2012 Samuel G. D. Williams. <http://www.oriontransfer.co.nz>
1
+ # Copyright, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
2
  #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  # of this software and associated documentation files (the "Software"), to deal
@@ -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
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2012 Samuel G. D. Williams. <http://www.oriontransfer.co.nz>
1
+ # Copyright, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
2
  #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  # of this software and associated documentation files (the "Software"), to deal
@@ -19,8 +19,8 @@
19
19
  # THE SOFTWARE.
20
20
 
21
21
  require 'rugged'
22
- require 'logger'
23
22
 
23
+ require_relative 'logger'
24
24
  require_relative 'dataset'
25
25
  require_relative 'changeset'
26
26
 
@@ -28,29 +28,48 @@ module Relaxo
28
28
  HEAD = 'HEAD'.freeze
29
29
 
30
30
  class Database
31
- def initialize(path, metadata = {})
31
+ def initialize(path, branch, metadata = {}, fsync: true)
32
32
  @path = path
33
33
  @metadata = metadata
34
34
 
35
- @logger = metadata[:logger] || Logger.new($stderr).tap{|logger| logger.level = Logger::INFO}
35
+ @repository = Rugged::Repository.new(path)
36
+ @repository.config['core.fsyncObjectFiles'] = fsync
36
37
 
37
- @repository = repository || Rugged::Repository.new(path)
38
+ @branch = branch
39
+ end
40
+
41
+ def config
42
+ @repository.config
38
43
  end
39
44
 
40
45
  attr :path
41
46
  attr :metadata
42
47
  attr :repository
43
48
 
49
+ # Completely clear out the database.
50
+ def clear!
51
+ if head = @repository.branches[@branch]
52
+ @repository.references.delete(head)
53
+ end
54
+ end
55
+
44
56
  def empty?
45
57
  @repository.empty?
46
58
  end
47
59
 
60
+ def head
61
+ @repository.branches[@branch]
62
+ end
63
+
48
64
  def [] key
49
65
  @metadata[key]
50
66
  end
51
67
 
52
68
  # During the execution of the block, changes don't get stored immediately, so reading from the dataset (from outside the block) will continue to return the values that were stored in the configuration when the transaction was started.
69
+ # @return the result of the block.
53
70
  def commit(**options)
71
+ result = nil
72
+
54
73
  track_time(options[:message]) do
55
74
  catch(:abort) do
56
75
  begin
@@ -58,10 +77,12 @@ module Relaxo
58
77
 
59
78
  changeset = Changeset.new(@repository, tree)
60
79
 
61
- yield changeset
80
+ result = yield changeset
62
81
  end until apply(parent, changeset, **options)
63
82
  end
64
83
  end
84
+
85
+ return result
65
86
  end
66
87
 
67
88
  # Efficient point-in-time read-only access.
@@ -113,7 +134,7 @@ module Relaxo
113
134
  end_time = Time.now
114
135
  elapsed_time = end_time - start_time
115
136
 
116
- @logger.debug("time") {"#{message.inspect}: %0.3fs" % elapsed_time}
137
+ Relaxo.logger.debug(self) {"#{message.inspect}: %0.3fs" % elapsed_time}
117
138
  end
118
139
 
119
140
  def apply(parent, changeset, **options)
@@ -121,7 +142,7 @@ module Relaxo
121
142
 
122
143
  options[:tree] = changeset.write_tree
123
144
  options[:parents] ||= [parent]
124
- options[:update_ref] ||= HEAD
145
+ options[:update_ref] ||= "refs/heads/#{@branch}"
125
146
 
126
147
  begin
127
148
  Rugged::Commit.create(@repository, options)
@@ -131,13 +152,11 @@ module Relaxo
131
152
  end
132
153
 
133
154
  def latest_commit
134
- if head = @repository.head
155
+ if head = self.head
135
156
  return head.target, head.target.tree
136
157
  else
137
158
  return nil, empty_tree
138
159
  end
139
- rescue Rugged::ReferenceError
140
- return nil, empty_tree
141
160
  end
142
161
 
143
162
  def empty_tree
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2012 Samuel G. D. Williams. <http://www.oriontransfer.co.nz>
1
+ # Copyright, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
2
  #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  # of this software and associated documentation files (the "Software"), to deal
@@ -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
@@ -1,4 +1,4 @@
1
- # Copyright, 2016, by Samuel G. D. Williams. <http://www.codeotaku.com>
1
+ # Copyright, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
2
  #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  # of this software and associated documentation files (the "Software"), to deal
@@ -18,32 +18,8 @@
18
18
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
19
  # THE SOFTWARE.
20
20
 
21
- require 'yaml'
21
+ require 'console'
22
22
 
23
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
24
+ extend Console
49
25
  end
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2012 Samuel G. D. Williams. <http://www.oriontransfer.co.nz>
1
+ # Copyright, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
2
  #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  # of this software and associated documentation files (the "Software"), to deal
@@ -19,5 +19,5 @@
19
19
  # THE SOFTWARE.
20
20
 
21
21
  module Relaxo
22
- VERSION = "1.0.1"
22
+ VERSION = "1.6.0"
23
23
  end
metadata CHANGED
@@ -1,15 +1,29 @@
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.6.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: 2020-05-29 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: console
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: rugged
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -25,35 +39,63 @@ dependencies:
25
39
  - !ruby/object:Gem::Version
26
40
  version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
- name: rspec
42
+ name: bake
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
- - - "~>"
45
+ - - ">="
32
46
  - !ruby/object:Gem::Version
33
- version: 3.4.0
47
+ version: '0'
34
48
  type: :development
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
- - - "~>"
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bake-bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: bake-modernize
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
39
81
  - !ruby/object:Gem::Version
40
- version: 3.4.0
82
+ version: '0'
41
83
  - !ruby/object:Gem::Dependency
42
84
  name: bundler
43
85
  requirement: !ruby/object:Gem::Requirement
44
86
  requirements:
45
- - - "~>"
87
+ - - ">="
46
88
  - !ruby/object:Gem::Version
47
- version: '1.3'
89
+ version: '0'
48
90
  type: :development
49
91
  prerelease: false
50
92
  version_requirements: !ruby/object:Gem::Requirement
51
93
  requirements:
52
- - - "~>"
94
+ - - ">="
53
95
  - !ruby/object:Gem::Version
54
- version: '1.3'
96
+ version: '0'
55
97
  - !ruby/object:Gem::Dependency
56
- name: rake
98
+ name: covered
57
99
  requirement: !ruby/object:Gem::Requirement
58
100
  requirements:
59
101
  - - ">="
@@ -66,44 +108,52 @@ dependencies:
66
108
  - - ">="
67
109
  - !ruby/object:Gem::Version
68
110
  version: '0'
69
- description: "\t\tRelaxo provides a set of tools and interfaces for interacting with
70
- CouchDB.\n\t\tIt aims to be as simple and efficient as possible while still improving
71
- the\n\t\tusability of various CouchDB features.\n"
72
- email:
73
- - samuel.williams@oriontransfer.co.nz
74
- executables:
75
- - relaxo
76
- - relaxo-admin
111
+ - !ruby/object:Gem::Dependency
112
+ name: msgpack
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rspec
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '3.6'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '3.6'
139
+ description:
140
+ email:
141
+ executables: []
77
142
  extensions: []
78
143
  extra_rdoc_files: []
79
144
  files:
80
- - ".gitignore"
81
- - ".rspec"
82
- - ".simplecov"
83
- - ".travis.yml"
84
- - Gemfile
85
- - README.md
86
- - Rakefile
87
- - bin/relaxo
88
- - bin/relaxo-admin
89
145
  - lib/relaxo.rb
90
146
  - lib/relaxo/changeset.rb
91
147
  - lib/relaxo/database.rb
92
148
  - lib/relaxo/dataset.rb
93
149
  - lib/relaxo/directory.rb
94
- - lib/relaxo/schema.rb
150
+ - lib/relaxo/logger.rb
95
151
  - lib/relaxo/version.rb
96
- - relaxo.gemspec
97
- - spec/relaxo/changeset_spec.rb
98
- - spec/relaxo/concurrency_spec.rb
99
- - spec/relaxo/database_spec.rb
100
- - spec/relaxo/enumeration_spec.rb
101
- - spec/relaxo/performance_spec.rb
102
- - spec/relaxo/test_records.rb
103
- homepage: ''
152
+ homepage: https://github.com/ioquatix/relaxo
104
153
  licenses:
105
154
  - MIT
106
- metadata: {}
155
+ metadata:
156
+ funding_uri: https://github.com/sponsors/ioquatix/
107
157
  post_install_message:
108
158
  rdoc_options: []
109
159
  require_paths:
@@ -112,22 +162,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
112
162
  requirements:
113
163
  - - ">="
114
164
  - !ruby/object:Gem::Version
115
- version: '0'
165
+ version: '2.5'
116
166
  required_rubygems_version: !ruby/object:Gem::Requirement
117
167
  requirements:
118
168
  - - ">="
119
169
  - !ruby/object:Gem::Version
120
170
  version: '0'
121
171
  requirements: []
122
- rubyforge_project:
123
- rubygems_version: 2.6.10
172
+ rubygems_version: 3.1.2
124
173
  signing_key:
125
174
  specification_version: 4
126
- summary: Relaxo is a helper for loading and working with CouchDB.
127
- test_files:
128
- - spec/relaxo/changeset_spec.rb
129
- - spec/relaxo/concurrency_spec.rb
130
- - spec/relaxo/database_spec.rb
131
- - spec/relaxo/enumeration_spec.rb
132
- - spec/relaxo/performance_spec.rb
133
- - spec/relaxo/test_records.rb
175
+ summary: Relaxo is versioned document database built on top of git.
176
+ test_files: []