paneron-register 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,96 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Paneron
4
+ module Register
5
+ module Writeable
6
+ # def self.included(base)
7
+ # base.class_eval do
8
+ # end
9
+ # end
10
+
11
+ # @return [Paneron::Register::Raw::Register] self
12
+ def save
13
+ unless parent.nil? || parent.path_valid?
14
+ raise Paneron::Register::Error, "Parent (#{parent.class.name}) is not valid"
15
+ end
16
+
17
+ if valid?
18
+ save_sequence
19
+ if !git_client.nil?
20
+ add_changes_to_staging
21
+ if has_uncommited_changes?
22
+ commit_changes("Update #{self.class.name}, from ruby-paneron-register")
23
+ end
24
+ end
25
+ else
26
+ raise Paneron::Register::Error, "#{self.class.name} is not valid:\n#{errors.map do |e|
27
+ " - #{e}"
28
+ end.join("\n")}"
29
+ end
30
+
31
+ self
32
+ end
33
+
34
+ def remote?
35
+ !git_url.nil? && git_url != ""
36
+ end
37
+
38
+ def pull_from_remote
39
+ git_client.pull(
40
+ nil, nil, rebase: true
41
+ )
42
+ end
43
+
44
+ def add_changes_to_staging
45
+ git_client.add
46
+ end
47
+
48
+ def has_uncommited_changes?
49
+ git_client.status.added.any?
50
+ end
51
+
52
+ def remote_branch_name
53
+ "#{@git_remote_name}/#{@git_branch}"
54
+ end
55
+
56
+ def has_unsynced_changes?
57
+ git_client.branches[remote_branch_name].nil? || git_client.branches[remote_branch_name].sha !=
58
+ git_client.gcommit("head").sha
59
+ end
60
+
61
+ def commit_changes(message = nil)
62
+ git_client.commit(message.nil? || message.empty? ? "Sync from ruby-paneron-register" : message)
63
+ end
64
+
65
+ def push_commits_to_remote
66
+ git_client.push
67
+ end
68
+
69
+ # Sync to remote
70
+ # @param [Boolean] update If true, rebase and pull before pushing
71
+ # @param [String] message Commit message
72
+ # @return [Paneron::Register::Raw::Register] self
73
+ def sync(update: false, message: nil)
74
+ if remote?
75
+ if update
76
+ pull_from_remote
77
+ end
78
+
79
+ add_changes_to_staging
80
+
81
+ if has_uncommited_changes?
82
+ commit_changes(message)
83
+ end
84
+
85
+ if has_unsynced_changes?
86
+ push_commits_to_remote
87
+ end
88
+ else
89
+ raise Paneron::Register::Error, "Cannot sync without a remote"
90
+ end
91
+ end
92
+
93
+ self
94
+ end
95
+ end
96
+ end
@@ -3,6 +3,11 @@
3
3
  require "paneron/register/version"
4
4
  require "paneron/register/error"
5
5
 
6
+ require "paneron/register/writeable"
7
+ require "paneron/register/validatable"
8
+ require "paneron/register/hierarchical"
9
+ require "paneron/register/root_finder"
10
+
6
11
  require "paneron/register/raw/item"
7
12
  require "paneron/register/raw/item_class"
8
13
  require "paneron/register/raw/data_set"
@@ -29,6 +29,7 @@ Gem::Specification.new do |spec|
29
29
 
30
30
  spec.add_runtime_dependency "git", "~> 2.3.1"
31
31
  spec.add_runtime_dependency "lutaml-model", "~> 0.3.18"
32
+ spec.add_runtime_dependency "uuid", "~> 2.3.9"
32
33
 
33
34
  spec.add_development_dependency "debug"
34
35
  spec.add_development_dependency "pry"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paneron-register
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-10-29 00:00:00.000000000 Z
11
+ date: 2024-11-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: git
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: 0.3.18
41
+ - !ruby/object:Gem::Dependency
42
+ name: uuid
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 2.3.9
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 2.3.9
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: debug
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -202,12 +216,14 @@ files:
202
216
  - LICENSE.txt
203
217
  - Makefile
204
218
  - README.adoc
219
+ - docs/examples.adoc
205
220
  - flake.lock
206
221
  - flake.nix
207
222
  - lib/paneron.rb
208
223
  - lib/paneron/register.rb
209
224
  - lib/paneron/register/data_set.rb
210
225
  - lib/paneron/register/error.rb
226
+ - lib/paneron/register/hierarchical.rb
211
227
  - lib/paneron/register/item.rb
212
228
  - lib/paneron/register/item_class.rb
213
229
  - lib/paneron/register/item_status.rb
@@ -221,7 +237,10 @@ files:
221
237
  - lib/paneron/register/raw/item_class.rb
222
238
  - lib/paneron/register/raw/register.rb
223
239
  - lib/paneron/register/register.rb
240
+ - lib/paneron/register/root_finder.rb
241
+ - lib/paneron/register/validatable.rb
224
242
  - lib/paneron/register/version.rb
243
+ - lib/paneron/register/writeable.rb
225
244
  - paneron-register.gemspec
226
245
  homepage: https://github.com/paneron/ruby-paneron-register
227
246
  licenses: