paneron-register 0.1.0 → 0.2.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
2
  SHA256:
3
- metadata.gz: 905511b3f9edd9a791524a1ef3093d5d51cd9c30732e9064098fd56eb513a966
4
- data.tar.gz: '094f4ac891e8f7501c9f07e33bbf26999945a90079ce1314a4cb643ee1363162'
3
+ metadata.gz: 52d7cfff231080db14c14453bd757db38f58b35ffcdbe69588c34fc97facc331
4
+ data.tar.gz: f5d14ee0605cc362800849f463a08bacf6cf2e1ef3a055244425b7264933bdf1
5
5
  SHA512:
6
- metadata.gz: a168bfaa534e93b2309e014b9329ad03701eae24504904aa52c78cf07322e321f9064bf3955e61c45a5acf655df359437a5b35ae98480ff47d60d1fbe964c4aa
7
- data.tar.gz: d3cfccc0ada0807ade6be6adb3104c619549991e1a46bd147b587a1d1deabde551cdb74080fa44c78f39d8d825205ffc3fae2e5e69df8e6b0dac4999807f017d
6
+ metadata.gz: 5a8588a75ec028ce6faa1083f615c120ed289a31924a19276383e8309ac40c2aa0733b299de94d1af23d98406faf67b06548351a605f2ead260ee1f927be30e7
7
+ data.tar.gz: '049798fcb8d8308ada3f45ce7effb8d960e3546890c5780c34178c5ad2bd94653f82be52f63a29945d3cf3b98d1b1a251055a1dec529b8056103c8da1ac5b268'
data/.rubocop.yml CHANGED
@@ -7,10 +7,16 @@ inherit_from:
7
7
  Layout/LineLength:
8
8
  Enabled: true
9
9
  AllowedPatterns: ["^\\s*#"]
10
+ Max: 95
10
11
 
11
12
  Metrics/MethodLength:
12
13
  Enabled: true
13
14
  CountAsOne: ["array", "hash", "heredoc", "method_call"]
15
+ Max: 35
16
+
17
+ Metrics/AbcSize:
18
+ Enabled: true
19
+ Max: 20
14
20
 
15
21
  Metrics/BlockLength:
16
22
  Enabled: true
data/README.adoc CHANGED
@@ -18,31 +18,70 @@ gem install paneron-register
18
18
  ```ruby
19
19
  require "paneron/register"
20
20
 
21
- # Initialize a new register
22
- # This example uses a working copy of Paneron's register.
23
- register = Paneron::Register::Register.new(
21
+ # Initialize a new data set
22
+ # This example uses a working copy of Paneron's data set.
23
+ # => Paneron::Register::Raw::DataSet
24
+ raw_data_set = Paneron::Register::Raw::DataSet.new(
24
25
  "/Users/username/Library/Application Support/Electron/working_copies/00000000-0001-0000-0000-000000000001",
25
- "register_name-1"
26
+ "data_set_name-1"
26
27
  )
27
28
 
28
- # Alternatively, initialize a new register root:
29
- root = Paneron::Register::RegisterRoot.new(
29
+ # => Paneron::Register::DataSet < Lutaml::Model::Serializable
30
+ data_set = raw_data_set.to_lutaml
31
+
32
+ # Alternatively, initialize a new register:
33
+ # => Paneron::Register::Raw::Register
34
+ raw_register = Paneron::Register::Raw::Register.new(
30
35
  "/Users/username/Library/Application Support/Electron/working_copies/00000000-0001-0000-0000-000000000001",
31
36
  )
32
- register = root.registries("register_name-1")
37
+
38
+ # This example uses a Git URL
39
+ # => Paneron::Register::Raw::Register
40
+ raw_register = Paneron::Register::Raw::Register.from_git(
41
+ "https://github.com/isogr/registry",
42
+
43
+ # optional. For previously cloned repos, pulls from repo iff true.
44
+ # update: true,
45
+ )
46
+
47
+ # => Paneron::Register::Raw::DataSet
48
+ raw_data_set = raw_register.data_sets("data_set_name-1")
49
+
50
+ # => Paneron::Register::DataSet < Lutaml::Model::Serializable
51
+ data_set = raw_data_set.to_lutaml
33
52
 
34
53
  # Get all item class objects
35
- register.item_classes
54
+ # => { item-class-name: Paneron::Register::Raw::ItemClass }
55
+ raw_data_set.item_classes
56
+
57
+ # => [ Paneron::Register::ItemClass ]
58
+ data_set.item_classes
36
59
 
37
60
  # Get a specific item class object
38
- item_class = register.item_classes("item-class-1")
61
+ # => Paneron::Register::Raw::ItemClass
62
+ raw_item_class = raw_data_set.item_classes("item-class-1")
63
+
64
+ # => Paneron::Register::ItemClass < Lutaml::Model::Serializable
65
+ item_class = raw_item_class.to_lutaml
39
66
 
40
- # Get all item class objects in Ruby Hash format
41
- item_class.items_yamls
67
+ # Get all item objects in Ruby Hash format
68
+ # => { item-uuid: Paneron::Register::Raw::Item }
69
+ raw_item_class.items
70
+
71
+ # => [ Paneron::Register::Item ]
72
+ item_class.items
42
73
 
43
74
  # Get a specific item property, using normal Ruby Hash methods
44
- id = item_class.items_yamls["id"]
45
- blob1 = item_class.items_yamls["data"]["blob1"]
75
+ # => Paneron::Register::Raw::Item
76
+ raw_item = raw_item_class.items["00000000-0000-0000-0000-000000000001"]
77
+ id = raw_item["id"]
78
+ blob1 = raw_item["data"]["blob1"]
79
+
80
+ # Get a specific item property, from a Lutaml object
81
+ # => Paneron::Register::Item < Lutaml::Model::Serializable
82
+ item = raw_item.to_lutaml
83
+ id = item.to_h["id"]
84
+ blob1 = item.to_h["data"]["blob1"]
46
85
  ```
47
86
 
48
87
  == License
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "lutaml/model"
4
+
5
+ module Paneron
6
+ module Register
7
+ class DataSet < Lutaml::Model::Serializable
8
+ attribute :name, Lutaml::Model::Type::String
9
+ attribute :item_classes, Paneron::Register::ItemClass, collection: true
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "lutaml/model"
4
+
5
+ module Paneron
6
+ module Register
7
+ class Item < Lutaml::Model::Serializable
8
+ # 'id' is a UUID
9
+ attribute :id, Lutaml::Model::Type::String
10
+
11
+ # TODO: data is free form object
12
+ attribute :data, Lutaml::Model::Type::String
13
+ attribute :status, Paneron::Register::ItemStatus, values:
14
+ Paneron::Register::ITEM_STATUSES.values
15
+ attribute :date_accepted, Lutaml::Model::Type::DateTime
16
+ end
17
+ end
18
+ end
@@ -1,51 +1,12 @@
1
- require "yaml"
1
+ # frozen_string_literal: true
2
+
3
+ require "lutaml/model"
2
4
 
3
5
  module Paneron
4
6
  module Register
5
- class ItemClass
6
- attr_reader :register_path, :register_root_path, :register_yaml_path,
7
- :item_class_name, :item_class_path, :register_name
8
-
9
- def initialize(register_root_path, register_name, item_class_name)
10
- File.join(register_root_path, register_name)
11
- item_class_path = File.join(register_root_path, register_name,
12
- item_class_name)
13
- self.class.validate_item_class_path(item_class_path)
14
- @item_class_path = item_class_path
15
- @items_uuids = nil
16
- @items = {}
17
- end
18
-
19
- def self.validate_item_class_path(path)
20
- unless File.exist?(path)
21
- raise Paneron::Register::Error,
22
- "Item class path does not exist"
23
- end
24
- unless File.directory?(path)
25
- raise Paneron::Register::Error,
26
- "Item class path is not a directory"
27
- end
28
- end
29
-
30
- def item_uuids
31
- @item_uuids ||= Dir.glob(File.join(item_class_path, "*.yaml"))
32
- .map { |file| File.basename(file, ".yaml") }
33
- end
34
-
35
- def item_yamls(uuid = nil)
36
- if uuid.nil?
37
- item_uuids.reduce({}) do |acc, uuid|
38
- acc[uuid] = item_yamls(uuid)
39
- acc
40
- end
41
- else
42
- @items[uuid] ||=
43
- YAML.safe_load_file(
44
- File.join(item_class_path, "#{uuid}.yaml"),
45
- permitted_classes: [Time],
46
- )
47
- end
48
- end
7
+ class ItemClass < Lutaml::Model::Serializable
8
+ attribute :name, Lutaml::Model::Type::String
9
+ attribute :items, Paneron::Register::Item, collection: true
49
10
  end
50
11
  end
51
12
  end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "lutaml/model"
4
+
5
+ module Paneron
6
+ module Register
7
+ class ItemStatus < Lutaml::Model::Serializable
8
+ attribute :state, :string
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Paneron
4
+ module Register
5
+ # From registry-kit
6
+ ITEM_STATUSES = {
7
+ INVALID: "invalid",
8
+ RETIRED: "retired",
9
+ SUBMITTED: "submitted",
10
+ SUPERSEDED: "superseded",
11
+ VALID: "valid",
12
+ }
13
+ .transform_values { |v| Paneron::Register::ItemStatus.new(state: v) }
14
+ .freeze
15
+ end
16
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "lutaml/model"
4
+
5
+ module Paneron
6
+ module Register
7
+ class Proposal < Lutaml::Model::Serializable
8
+ attribute :uuid, Lutaml::Model::Type::String
9
+ attribute :date_accepted, Lutaml::Model::Type::DateTime
10
+ attribute :state, Paneron::Register::ProposalState, values:
11
+ Paneron::Register::PROPOSAL_STATES.values
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "lutaml/model"
4
+
5
+ module Paneron
6
+ module Register
7
+ class ProposalState < Lutaml::Model::Serializable
8
+ attribute :state, :string
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Paneron
4
+ module Register
5
+ # From registry-kit
6
+ PROPOSAL_STATES = {
7
+ DRAFT: "draft",
8
+ PROPOSED: "proposed",
9
+ SUBMITTED_FOR_CONTROL_BODY_REVIEW: "pending-control-body-review",
10
+ RETURNED_FOR_CLARIFICATION: "returned-for-clarification",
11
+ ACCEPTED: "accepted",
12
+ REJECTED: "rejected",
13
+ APPEALED: "rejection-appealed-to-owner",
14
+ WITHDRAWN: "withdrawn",
15
+ ACCEPTED_ON_APPEAL: "accepted-on-appeal",
16
+ REJECTION_UPHELD_ON_APPEAL: "rejection-upheld-on-appeal",
17
+ APPEAL_WITHDRAWN: "appeal-withdrawn",
18
+ }
19
+ .transform_values { |v| Paneron::Register::ProposalState.new(state: v) }
20
+ .freeze
21
+ end
22
+ end
@@ -0,0 +1,93 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "yaml"
4
+
5
+ module Paneron
6
+ module Register
7
+ module Raw
8
+ class DataSet
9
+ attr_reader :data_set_path, :register_path, :data_set_yaml_path,
10
+ :data_set_name, :extension
11
+
12
+ def initialize(register_path, data_set_name, extension = "yaml")
13
+ data_set_path = File.join(register_path, data_set_name)
14
+ self.class.validate_data_set_path(data_set_path)
15
+
16
+ @register_path = register_path
17
+ @data_set_name = data_set_name
18
+ @extension = extension
19
+ @data_set_path = data_set_path
20
+ @data_set_yaml_path = File.join(data_set_path,
21
+ DATA_SET_METADATA_FILENAME)
22
+ @item_classes = {}
23
+ @item_class_names = nil
24
+ @item_uuids = nil
25
+ @metadata = nil
26
+ end
27
+
28
+ DATA_SET_METADATA_FILENAME = "/register.yaml"
29
+
30
+ def self.validate_data_set_path(data_set_path)
31
+ unless File.exist?(data_set_path)
32
+ raise Paneron::Register::Error,
33
+ "Data Set path does not exist"
34
+ end
35
+ unless File.directory?(data_set_path)
36
+ raise Paneron::Register::Error,
37
+ "Data Set path is not a directory"
38
+ end
39
+ unless File.exist?(File.join(
40
+ data_set_path, DATA_SET_METADATA_FILENAME
41
+ ))
42
+ raise Paneron::Register::Error,
43
+ "Data Set metadata file does not exist"
44
+ end
45
+ end
46
+
47
+ def to_lutaml
48
+ Paneron::Register::DataSet.new(
49
+ name: data_set_name,
50
+ item_classes: item_class_lutamls,
51
+ )
52
+ end
53
+
54
+ def item_class_lutamls
55
+ item_classes.map do |_item_class_name, item_class|
56
+ item_class.to_lutaml
57
+ end
58
+ end
59
+
60
+ def item_classes(item_class_name = nil)
61
+ if item_class_name.nil?
62
+ item_class_names.reduce({}) do |acc, item_class_name|
63
+ acc[item_class_name] = item_classes(item_class_name)
64
+ acc
65
+ end
66
+ else
67
+ @item_classes[item_class_name] ||=
68
+ Paneron::Register::Raw::ItemClass.new(
69
+ data_set_path, item_class_name
70
+ )
71
+ end
72
+ end
73
+
74
+ def item_class_names
75
+ @item_class_names ||=
76
+ Dir.glob(File.join(data_set_path, "*/*.#{extension}"))
77
+ .map { |file| File.basename(File.dirname(file)) }.uniq
78
+ end
79
+
80
+ def item_uuids
81
+ item_classes.values.map(&:item_uuids).flatten
82
+ end
83
+
84
+ def metadata
85
+ @metadata ||= YAML.safe_load_file(
86
+ data_set_yaml_path,
87
+ permitted_classes: [Time],
88
+ )
89
+ end
90
+ end
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "yaml"
4
+
5
+ module Paneron
6
+ module Register
7
+ module Raw
8
+ class Item
9
+ attr_reader :item_class_path,
10
+ :item_id,
11
+ :item_path,
12
+ :extension
13
+
14
+ def initialize(
15
+ item_class_path,
16
+ item_id,
17
+ extension = "yaml"
18
+ )
19
+ item_path = File.join(item_class_path, "#{item_id}.#{extension}")
20
+ self.class.validate_item_path(item_path)
21
+ @item_class_path = item_class_path
22
+ @item_id = item_id
23
+ @item_path = item_path
24
+ @extension = extension
25
+ @to_h = nil
26
+ end
27
+
28
+ def self.validate_item_path(path)
29
+ unless File.exist?(path)
30
+ raise Paneron::Register::Error,
31
+ "Item path does not exist"
32
+ end
33
+ unless File.file?(path)
34
+ raise Paneron::Register::Error,
35
+ "Item path is not a file"
36
+ end
37
+ end
38
+
39
+ def to_lutaml
40
+ Paneron::Register::Item.new(
41
+ id: item_id,
42
+ data: to_h["data"],
43
+ status: Paneron::Register::ItemStatus.new(state: to_h["status"]),
44
+ date_accepted: to_h["dateAccepted"].to_s,
45
+ )
46
+ end
47
+
48
+ def to_h
49
+ @to_h ||=
50
+ YAML.safe_load_file(
51
+ File.join(item_path),
52
+ permitted_classes: [Time],
53
+ )
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "yaml"
4
+
5
+ module Paneron
6
+ module Register
7
+ module Raw
8
+ class ItemClass
9
+ attr_reader :data_set_path,
10
+ :item_class_name, :item_class_path, :extension
11
+
12
+ def initialize(
13
+ data_set_path,
14
+ item_class_name,
15
+ extension = "yaml"
16
+ )
17
+ item_class_path = File.join(data_set_path, item_class_name)
18
+ self.class.validate_item_class_path(item_class_path)
19
+ @extension = extension
20
+ @data_set_path = data_set_path
21
+ @item_class_name = item_class_name
22
+ @item_class_path = item_class_path
23
+ @items_uuids = nil
24
+ @items = {}
25
+ end
26
+
27
+ def self.validate_item_class_path(path)
28
+ unless File.exist?(path)
29
+ raise Paneron::Register::Error,
30
+ "Item class path does not exist"
31
+ end
32
+ unless File.directory?(path)
33
+ raise Paneron::Register::Error,
34
+ "Item class path is not a directory"
35
+ end
36
+ end
37
+
38
+ def to_lutaml
39
+ Paneron::Register::ItemClass.new(
40
+ name: item_class_name,
41
+ items: item_lutamls,
42
+ )
43
+ end
44
+
45
+ def item_uuids
46
+ @item_uuids ||= Dir.glob(File.join(item_class_path, "*.#{extension}"))
47
+ .map { |file| File.basename(file, ".#{extension}") }
48
+ end
49
+
50
+ def items(uuid = nil)
51
+ if uuid.nil?
52
+ item_uuids.reduce({}) do |acc, uuid|
53
+ acc[uuid] = items(uuid)
54
+ acc
55
+ end
56
+ else
57
+ @items[uuid] ||=
58
+ Paneron::Register::Raw::Item.new(
59
+ item_class_path, uuid
60
+ )
61
+ end
62
+ end
63
+
64
+ def item_lutamls
65
+ items.values.map(&:to_lutaml)
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,154 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "yaml"
4
+
5
+ module Paneron
6
+ module Register
7
+ module Raw
8
+ class Register
9
+ attr_reader :register_path, :register_yaml_path
10
+
11
+ def initialize(register_path)
12
+ self.class.validate_path(register_path)
13
+ @register_path = register_path
14
+ @register_yaml_path = File.join(register_path,
15
+ REGISTER_METADATA_FILENAME)
16
+ @data_set_names = nil
17
+ @data_sets = {}
18
+ @metadata = nil
19
+ end
20
+
21
+ def self.local_cache_path
22
+ case RUBY_PLATFORM
23
+ when /darwin/
24
+ File.join(
25
+ `command getconf DARWIN_USER_CACHE_DIR`.chomp,
26
+ "com.paneron.ruby-paneron-register",
27
+ )
28
+ else
29
+ File.join(
30
+ Dir.exist?(ENV["XDG_CACHE_HOME"]) ? ENV["XDG_CACHE_HOME"] : "~/.cache",
31
+ "ruby-paneron-register",
32
+ )
33
+ end
34
+ end
35
+
36
+ def self.setup_cache_path
37
+ if !Dir.exist?(local_cache_path)
38
+ require "fileutils"
39
+ FileUtils.mkdir_p(local_cache_path)
40
+ end
41
+ end
42
+
43
+ def self.calculate_repo_cache_hash(repo_url)
44
+ require "digest"
45
+ require "base64"
46
+ digest = [Digest::SHA1.hexdigest(repo_url)].pack("H*")
47
+ Base64.encode64(digest).tr("+/= ", "_-")[0..16]
48
+ end
49
+
50
+ def self.from_git(repo_url, update: true)
51
+ require "git"
52
+ setup_cache_path
53
+ repo_cache_name =
54
+ "#{File.basename(repo_url)}-#{calculate_repo_cache_hash(repo_url)}"
55
+
56
+ # Check if repo is already cloned
57
+ full_local_cache_path = File.join(local_cache_path, repo_cache_name)
58
+ g = begin
59
+ if File.exist?(full_local_cache_path)
60
+ _g = Git.open(full_local_cache_path)
61
+
62
+ # Pull-rebase to update it
63
+ if update
64
+ _g.pull(
65
+ nil, nil, rebase: true
66
+ )
67
+ end
68
+ _g
69
+ else
70
+ Git.clone(
71
+ repo_url,
72
+ repo_cache_name,
73
+ path: local_cache_path,
74
+ # timeout: 30,
75
+ )
76
+ end
77
+ rescue Git::TimeoutError => e
78
+ e.result.tap do |_r|
79
+ warn "Timed out trying to clone #{repo_url}."
80
+ raise e
81
+ end
82
+ end
83
+
84
+ new(g.dir.path)
85
+ end
86
+
87
+ REGISTER_METADATA_FILENAME = "/paneron.yaml"
88
+
89
+ def self.validate_path(register_path)
90
+ unless File.exist?(register_path)
91
+ raise Paneron::Register::Error,
92
+ "Register path does not exist"
93
+ end
94
+ unless File.directory?(register_path)
95
+ raise Paneron::Register::Error,
96
+ "Register path is not a directory"
97
+ end
98
+ unless File.exist?(File.join(
99
+ register_path, REGISTER_METADATA_FILENAME
100
+ ))
101
+ raise Paneron::Register::Error,
102
+ "Register metadata file does not exist"
103
+ end
104
+ end
105
+
106
+ def to_lutaml
107
+ Paneron::Register::Register.new(
108
+ data_sets: data_set_lutamls,
109
+ metadata: metadata.to_json,
110
+ )
111
+ end
112
+
113
+ def data_set_names
114
+ @data_set_names ||= Dir.glob(
115
+ File.join(
116
+ register_path,
117
+ "*#{Paneron::Register::Raw::DataSet::DATA_SET_METADATA_FILENAME}",
118
+ ),
119
+ )
120
+ .map do |file|
121
+ File.basename(File.dirname(file))
122
+ end
123
+ end
124
+
125
+ def data_set_path(data_set_name)
126
+ File.join(register_path, data_set_name)
127
+ end
128
+
129
+ def metadata
130
+ @metadata ||= YAML.safe_load_file(register_yaml_path)
131
+ end
132
+
133
+ def data_sets(data_set_name = nil)
134
+ if data_set_name.nil?
135
+ data_set_names.reduce({}) do |acc, data_set_name|
136
+ acc[data_set_name] = data_sets(data_set_name)
137
+ acc
138
+ end
139
+ else
140
+ @data_sets[data_set_name] ||=
141
+ Paneron::Register::Raw::DataSet.new(register_path,
142
+ data_set_name)
143
+ end
144
+ end
145
+
146
+ def data_set_lutamls
147
+ data_sets.map do |_data_set_name, data_set|
148
+ data_set.to_lutaml
149
+ end
150
+ end
151
+ end
152
+ end
153
+ end
154
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Paneron::Register::Raw module
4
+ module Paneron
5
+ module Register
6
+ module Raw; end
7
+ end
8
+ end
@@ -1,73 +1,14 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "yaml"
2
4
 
5
+ require "lutaml/model"
6
+
3
7
  module Paneron
4
8
  module Register
5
- class Register
6
- attr_reader :register_path, :register_root_path, :register_yaml_path,
7
- :register_name
8
-
9
- def initialize(register_root_path, register_name)
10
- register_path = File.join(register_root_path, register_name)
11
- self.class.validate_register_path(register_path)
12
- @register_name = register_name
13
- @register_root_path = register_root_path
14
- @register_path = register_path
15
- @register_yaml_path = File.join(register_path,
16
- REGISTER_METADATA_FILENAME)
17
- @item_classes = {}
18
- @item_class_names = nil
19
- @item_uuids = nil
20
- end
21
-
22
- REGISTER_METADATA_FILENAME = "/register.yaml".freeze
23
-
24
- def self.validate_register_path(register_path)
25
- unless File.exist?(register_path)
26
- raise Paneron::Register::Error,
27
- "Register path does not exist"
28
- end
29
- unless File.directory?(register_path)
30
- raise Paneron::Register::Error,
31
- "Register path is not a directory"
32
- end
33
- unless File.exist?(File.join(
34
- register_path, REGISTER_METADATA_FILENAME
35
- ))
36
- raise Paneron::Register::Error,
37
- "Register metadata file does not exist"
38
- end
39
- end
40
-
41
- def item_classes(item_class_name = nil)
42
- if item_class_name.nil?
43
- item_class_names.reduce({}) do |acc, item_class_name|
44
- acc[item_class_name] = item_classes(item_class_name)
45
- acc
46
- end
47
- else
48
- @item_classes[item_class_name] ||=
49
- Paneron::Register::ItemClass.new(
50
- register_root_path, register_name, item_class_name
51
- )
52
- end
53
- end
54
-
55
- def item_class_names
56
- @item_class_names ||=
57
- Dir.glob(File.join(register_path, "*/*.yaml"))
58
- .map { |file| File.basename(File.dirname(file)) }.uniq
59
- end
60
-
61
- def item_uuids
62
- item_classes.values.map(&:item_uuids).flatten
63
- end
64
-
65
- def get_metadata_yaml
66
- YAML.safe_load_file(
67
- register_yaml_path,
68
- permitted_classes: [Time],
69
- )
70
- end
9
+ class Register < Lutaml::Model::Serializable
10
+ attribute :data_sets, Paneron::Register::DataSet, collection: true
11
+ attribute :metadata, Lutaml::Model::Type::String
71
12
  end
72
13
  end
73
14
  end
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Paneron
2
4
  module Register
3
- VERSION = "0.1.0".freeze
5
+ VERSION = "0.2.0"
4
6
  end
5
7
  end
@@ -2,9 +2,20 @@
2
2
 
3
3
  require "paneron/register/version"
4
4
  require "paneron/register/error"
5
- require "paneron/register/register"
6
- require "paneron/register/register_root"
5
+
6
+ require "paneron/register/raw/item"
7
+ require "paneron/register/raw/item_class"
8
+ require "paneron/register/raw/data_set"
9
+ require "paneron/register/raw/register"
10
+
11
+ require "paneron/register/proposal_state"
12
+ require "paneron/register/proposal_states"
13
+ require "paneron/register/item_status"
14
+ require "paneron/register/item_statuses"
15
+ require "paneron/register/item"
7
16
  require "paneron/register/item_class"
17
+ require "paneron/register/data_set"
18
+ require "paneron/register/register"
8
19
 
9
20
  # Paneron::Register module
10
21
  module Paneron
data/lib/paneron.rb CHANGED
@@ -1 +1,3 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Paneron; end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  lib = File.expand_path("lib", __dir__)
2
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
5
  require "paneron/register/version"
@@ -25,6 +27,9 @@ Gem::Specification.new do |spec|
25
27
 
26
28
  # spec.add_runtime_dependency "yaml"
27
29
 
30
+ spec.add_runtime_dependency "git", "~> 2.3.1"
31
+ spec.add_runtime_dependency "lutaml-model", "~> 0.3.18"
32
+
28
33
  spec.add_development_dependency "debug"
29
34
  spec.add_development_dependency "pry"
30
35
  spec.add_development_dependency "rake", "~> 13.0"
metadata CHANGED
@@ -1,15 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paneron-register
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.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-17 00:00:00.000000000 Z
11
+ date: 2024-10-29 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: git
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 2.3.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 2.3.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: lutaml-model
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.3.18
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.3.18
13
41
  - !ruby/object:Gem::Dependency
14
42
  name: debug
15
43
  requirement: !ruby/object:Gem::Requirement
@@ -178,10 +206,21 @@ files:
178
206
  - flake.nix
179
207
  - lib/paneron.rb
180
208
  - lib/paneron/register.rb
209
+ - lib/paneron/register/data_set.rb
181
210
  - lib/paneron/register/error.rb
211
+ - lib/paneron/register/item.rb
182
212
  - lib/paneron/register/item_class.rb
213
+ - lib/paneron/register/item_status.rb
214
+ - lib/paneron/register/item_statuses.rb
215
+ - lib/paneron/register/proposal.rb
216
+ - lib/paneron/register/proposal_state.rb
217
+ - lib/paneron/register/proposal_states.rb
218
+ - lib/paneron/register/raw.rb
219
+ - lib/paneron/register/raw/data_set.rb
220
+ - lib/paneron/register/raw/item.rb
221
+ - lib/paneron/register/raw/item_class.rb
222
+ - lib/paneron/register/raw/register.rb
183
223
  - lib/paneron/register/register.rb
184
- - lib/paneron/register/register_root.rb
185
224
  - lib/paneron/register/version.rb
186
225
  - paneron-register.gemspec
187
226
  homepage: https://github.com/paneron/ruby-paneron-register
@@ -1,79 +0,0 @@
1
- require "yaml"
2
-
3
- module Paneron
4
- module Register
5
- class RegisterRoot
6
- attr_reader :register_root_path, :register_root_yaml_path
7
-
8
- def initialize(register_root_path)
9
- self.class.validate_root_path(register_root_path)
10
- @register_root_path = register_root_path
11
- @register_root_yaml_path = File.join(register_root_path,
12
- REGISTER_ROOT_METADATA_FILENAME)
13
- @register_names = nil
14
- @registries = {}
15
- end
16
-
17
- REGISTER_ROOT_METADATA_FILENAME = "/paneron.yaml".freeze
18
-
19
- def self.validate_root_path(register_root_path)
20
- unless File.exist?(register_root_path)
21
- raise Paneron::Register::Error,
22
- "Register root path does not exist"
23
- end
24
- unless File.directory?(register_root_path)
25
- raise Paneron::Register::Error,
26
- "Register root path is not a directory"
27
- end
28
- unless File.exist?(File.join(
29
- register_root_path, REGISTER_ROOT_METADATA_FILENAME
30
- ))
31
- raise Paneron::Register::Error,
32
- "Register root metadata file does not exist"
33
- end
34
- end
35
-
36
- def register_names
37
- @register_names ||= Dir.glob(
38
- File.join(
39
- register_root_path,
40
- "*#{Paneron::Register::Register::REGISTER_METADATA_FILENAME}",
41
- ),
42
- )
43
- .map do |file|
44
- File.basename(File.dirname(file))
45
- end
46
- end
47
-
48
- def register_path(register_name)
49
- File.join(register_root_path, register_name)
50
- end
51
-
52
- def get_root_metadata
53
- YAML.safe_load_file(register_root_yaml_path)
54
- end
55
-
56
- def registries(register_name = nil)
57
- if register_name.nil?
58
- register_names.reduce({}) do |acc, register_name|
59
- acc[register_name] = registries(register_name)
60
- acc
61
- end
62
- else
63
- @registries[register_name] ||=
64
- Paneron::Register::Register.new(register_root_path,
65
- register_name)
66
- end
67
- end
68
-
69
- def register_metadata_yaml(register_name)
70
- registires(register_name).get_metadata_yaml
71
-
72
- YAML.safe_load_file(
73
- register_yaml_path(register_name),
74
- permitted_classes: [Time],
75
- )
76
- end
77
- end
78
- end
79
- end