paneron-register 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 905511b3f9edd9a791524a1ef3093d5d51cd9c30732e9064098fd56eb513a966
4
+ data.tar.gz: '094f4ac891e8f7501c9f07e33bbf26999945a90079ce1314a4cb643ee1363162'
5
+ SHA512:
6
+ metadata.gz: a168bfaa534e93b2309e014b9329ad03701eae24504904aa52c78cf07322e321f9064bf3955e61c45a5acf655df359437a5b35ae98480ff47d60d1fbe964c4aa
7
+ data.tar.gz: d3cfccc0ada0807ade6be6adb3104c619549991e1a46bd147b587a1d1deabde551cdb74080fa44c78f39d8d825205ffc3fae2e5e69df8e6b0dac4999807f017d
data/.editorconfig ADDED
@@ -0,0 +1,13 @@
1
+ # EditorConfig helps developers define and maintain consistent
2
+ # coding styles between different editors and IDEs
3
+ # editorconfig.org
4
+
5
+ root = true
6
+
7
+ [*]
8
+ end_of_line = lf
9
+ charset = utf-8
10
+ trim_trailing_whitespace = true
11
+ insert_final_newline = true
12
+ indent_style = space
13
+ indent_size = 2
data/.envrc ADDED
@@ -0,0 +1 @@
1
+ use flake
data/.gitattributes ADDED
@@ -0,0 +1 @@
1
+ * text=auto eol=lf
data/.gitignore ADDED
@@ -0,0 +1,66 @@
1
+ # Nix flake
2
+ /result/
3
+
4
+ # direnv
5
+ .direnv/
6
+
7
+ # rspec failure tracking
8
+ .rspec_status
9
+
10
+ # Ruby
11
+ *.gem
12
+ *.rbc
13
+ /.config
14
+ /coverage/
15
+ /InstalledFiles
16
+ /pkg/
17
+ /spec/reports/
18
+ /spec/examples.txt
19
+ /test/tmp/
20
+ /test/version_tmp/
21
+ /tmp/
22
+
23
+ # Used by dotenv library to load environment variables.
24
+ # .env
25
+
26
+ # Ignore Byebug command history file.
27
+ .byebug_history
28
+
29
+ ## Specific to RubyMotion:
30
+ .dat*
31
+ .repl_history
32
+ build/
33
+ *.bridgesupport
34
+ build-iPhoneOS/
35
+ build-iPhoneSimulator/
36
+
37
+ ## Specific to RubyMotion (use of CocoaPods):
38
+ #
39
+ # We recommend against adding the Pods directory to your .gitignore. However
40
+ # you should judge for yourself, the pros and cons are mentioned at:
41
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
42
+ #
43
+ # vendor/Pods/
44
+
45
+ ## Documentation cache and generated files:
46
+ /.yardoc/
47
+ /_yardoc/
48
+ /doc/
49
+ /rdoc/
50
+
51
+ ## Environment normalization:
52
+ /.bundle/
53
+ /vendor/bundle
54
+ /lib/bundler/man/
55
+
56
+ # for a library or gem, you might want to ignore these files since the code is
57
+ # intended to run in multiple environments; otherwise, check them in:
58
+ Gemfile.lock
59
+ .ruby-version
60
+ .ruby-gemset
61
+
62
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
63
+ .rvmrc
64
+
65
+ # Used by RuboCop. Remote config files pulled in from inherit_from directive.
66
+ .rubocop-https?--*
data/.hound.yml ADDED
@@ -0,0 +1,3 @@
1
+ ruby:
2
+ enabled: true
3
+ config_file: .rubocop.yml
data/.irbrc ADDED
@@ -0,0 +1 @@
1
+ require "paneron/register"
data/.pryrc ADDED
@@ -0,0 +1 @@
1
+ require "paneron/register"
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,40 @@
1
+ inherit_from:
2
+ - https://raw.githubusercontent.com/riboseinc/oss-guides/master/ci/rubocop.yml
3
+
4
+ # local repo-specific modifications
5
+ # ...
6
+
7
+ Layout/LineLength:
8
+ Enabled: true
9
+ AllowedPatterns: ["^\\s*#"]
10
+
11
+ Metrics/MethodLength:
12
+ Enabled: true
13
+ CountAsOne: ["array", "hash", "heredoc", "method_call"]
14
+
15
+ Metrics/BlockLength:
16
+ Enabled: true
17
+ Exclude: [ "**/*.gemspec", "spec/**" ]
18
+
19
+ Layout/MultilineHashKeyLineBreaks:
20
+ Enabled: true
21
+ AllowMultilineFinalElement: false
22
+
23
+ Layout/FirstHashElementLineBreak:
24
+ Enabled: true
25
+ AllowMultilineFinalElement: false
26
+
27
+ Layout/MultilineArrayLineBreaks:
28
+ Enabled: true
29
+ AllowMultilineFinalElement: false
30
+
31
+ Layout/FirstHashElementIndentation:
32
+ Enabled: true
33
+ EnforcedStyle: consistent
34
+
35
+ Layout/FirstArrayElementIndentation:
36
+ Enabled: true
37
+ EnforcedStyle: consistent
38
+
39
+ AllCops:
40
+ TargetRubyVersion: 3.1
data/CHANGELOG.adoc ADDED
File without changes
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ Encoding.default_external = Encoding::UTF_8
2
+ Encoding.default_internal = Encoding::UTF_8
3
+
4
+ source "https://rubygems.org"
5
+ git_source(:github) { |repo| "https://github.com/#{repo}" }
6
+
7
+ gemspec
8
+
9
+ begin
10
+ eval_gemfile("Gemfile.devel")
11
+ rescue StandardError
12
+ nil
13
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,25 @@
1
+ BSD 2-Clause License
2
+
3
+ Copyright (c) 2024, Ribose
4
+ All rights reserved.
5
+
6
+ Redistribution and use in source and binary forms, with or without
7
+ modification, are permitted provided that the following conditions are met:
8
+
9
+ * Redistributions of source code must retain the above copyright notice, this
10
+ list of conditions and the following disclaimer.
11
+
12
+ * Redistributions in binary form must reproduce the above copyright notice,
13
+ this list of conditions and the following disclaimer in the documentation
14
+ and/or other materials provided with the distribution.
15
+
16
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
20
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/Makefile ADDED
@@ -0,0 +1,66 @@
1
+ # https://gist.github.com/klmr/575726c7e05d8780505a
2
+ # Inspired by
3
+ # <http://marmelab.com/blog/2016/02/29/auto-documented-makefile.html>
4
+ # sed script explained:
5
+ # /^##/:
6
+ # * save line in hold space
7
+ # * purge line
8
+ # * Loop:
9
+ # * append newline + line to hold space
10
+ # * go to next line
11
+ # * if line starts with doc comment, strip comment character off and loop
12
+ # * remove target prerequisites
13
+ # * append hold space (+ newline) to line
14
+ # * replace newline plus comments by
15
+ # * print line
16
+ # Separate expressions are necessary because labels cannot be delimited by
17
+ # semicolon; see <http://stackoverflow.com/a/11799865/1968>
18
+ .PHONY: show-help
19
+ show-help:
20
+ @echo "$$(tput bold)Available rules:$$(tput sgr0)"
21
+ @echo
22
+ @sed -n -e "/^## / { \
23
+ h; \
24
+ s/.*//; \
25
+ :doc" \
26
+ -e "H; \
27
+ n; \
28
+ s/^## //; \
29
+ t doc" \
30
+ -e "s/:.*//; \
31
+ G; \
32
+ s/\\n## /---/; \
33
+ s/\\n/ /g; \
34
+ p; \
35
+ }" ${MAKEFILE_LIST} \
36
+ | LC_ALL='C' sort --ignore-case \
37
+ | awk -F '---' \
38
+ -v ncol=$$(tput cols) \
39
+ -v indent=19 \
40
+ -v col_on="$$(tput setaf 6)" \
41
+ -v col_off="$$(tput sgr0)" \
42
+ '{ \
43
+ printf "%s%*s%s ", col_on, -indent, $$1, col_off; \
44
+ n = split($$2, words, " "); \
45
+ line_length = ncol - indent; \
46
+ for (i = 1; i <= n; i++) { \
47
+ line_length -= length(words[i]) + 1; \
48
+ if (line_length <= 0) { \
49
+ line_length = ncol - indent - length(words[i]) - 1; \
50
+ printf "\n%*s ", -indent, " "; \
51
+ } \
52
+ printf "%s ", words[i]; \
53
+ } \
54
+ printf "\n"; \
55
+ }' \
56
+ | more $(shell test $(shell uname) == Darwin && echo '--no-init --raw-control-chars')
57
+
58
+ .PHONY: test
59
+ ## Run tests
60
+ test:
61
+ bundle exec rspec
62
+
63
+ .PHONY: update-flakes
64
+ ## Update all flakes
65
+ update-flakes:
66
+ nix flake update
data/README.adoc ADDED
@@ -0,0 +1,50 @@
1
+ = Paneron Register Ruby Gem
2
+
3
+ image:https://img.shields.io/gem/v/paneron-register.svg["Gem Version", link="https://rubygems.org/gems/paneron-register"]
4
+ image:https://github.com/paneron/ruby-paneron-register/actions/workflows/test.yaml/badge.svg["Build Status",Link="https://github.com/paneron/ruby-paneron-register/actions/workflows/test.yaml"]
5
+ image:https://codeclimate.com/github/paneron/ruby-paneron-register/badges/gpa.svg["Code Climate", link="https://codeclimate.com/github/paneron/ruby-paneron-register"]
6
+ image:https://img.shields.io/github/issues-pr-raw/paneron/ruby-paneron-register.svg["Pull Requests", link="https://github.com/paneron/ruby-paneron-register/pulls"]
7
+ image:https://img.shields.io/github/commits-since/paneron/ruby-paneron-register/latest.svg["Commits since latest",link="https://github.com/paneron/ruby-paneron-register/releases"]
8
+
9
+
10
+ == Installation
11
+
12
+ ```sh
13
+ gem install paneron-register
14
+ ```
15
+
16
+ == Usage
17
+
18
+ ```ruby
19
+ require "paneron/register"
20
+
21
+ # Initialize a new register
22
+ # This example uses a working copy of Paneron's register.
23
+ register = Paneron::Register::Register.new(
24
+ "/Users/username/Library/Application Support/Electron/working_copies/00000000-0001-0000-0000-000000000001",
25
+ "register_name-1"
26
+ )
27
+
28
+ # Alternatively, initialize a new register root:
29
+ root = Paneron::Register::RegisterRoot.new(
30
+ "/Users/username/Library/Application Support/Electron/working_copies/00000000-0001-0000-0000-000000000001",
31
+ )
32
+ register = root.registries("register_name-1")
33
+
34
+ # Get all item class objects
35
+ register.item_classes
36
+
37
+ # Get a specific item class object
38
+ item_class = register.item_classes("item-class-1")
39
+
40
+ # Get all item class objects in Ruby Hash format
41
+ item_class.items_yamls
42
+
43
+ # 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"]
46
+ ```
47
+
48
+ == License
49
+
50
+ See LICENSE.txt
data/flake.lock ADDED
@@ -0,0 +1,148 @@
1
+ {
2
+ "nodes": {
3
+ "devshell": {
4
+ "inputs": {
5
+ "flake-utils": "flake-utils",
6
+ "nixpkgs": "nixpkgs"
7
+ },
8
+ "locked": {
9
+ "lastModified": 1713532798,
10
+ "narHash": "sha256-wtBhsdMJA3Wa32Wtm1eeo84GejtI43pMrFrmwLXrsEc=",
11
+ "owner": "numtide",
12
+ "repo": "devshell",
13
+ "rev": "12e914740a25ea1891ec619bb53cf5e6ca922e40",
14
+ "type": "github"
15
+ },
16
+ "original": {
17
+ "owner": "numtide",
18
+ "ref": "main",
19
+ "repo": "devshell",
20
+ "type": "github"
21
+ }
22
+ },
23
+ "flake-compat": {
24
+ "flake": false,
25
+ "locked": {
26
+ "lastModified": 1696426674,
27
+ "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=",
28
+ "owner": "edolstra",
29
+ "repo": "flake-compat",
30
+ "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33",
31
+ "type": "github"
32
+ },
33
+ "original": {
34
+ "owner": "edolstra",
35
+ "repo": "flake-compat",
36
+ "type": "github"
37
+ }
38
+ },
39
+ "flake-utils": {
40
+ "inputs": {
41
+ "systems": "systems"
42
+ },
43
+ "locked": {
44
+ "lastModified": 1701680307,
45
+ "narHash": "sha256-kAuep2h5ajznlPMD9rnQyffWG8EM/C73lejGofXvdM8=",
46
+ "owner": "numtide",
47
+ "repo": "flake-utils",
48
+ "rev": "4022d587cbbfd70fe950c1e2083a02621806a725",
49
+ "type": "github"
50
+ },
51
+ "original": {
52
+ "owner": "numtide",
53
+ "repo": "flake-utils",
54
+ "type": "github"
55
+ }
56
+ },
57
+ "flake-utils_2": {
58
+ "inputs": {
59
+ "systems": "systems_2"
60
+ },
61
+ "locked": {
62
+ "lastModified": 1710146030,
63
+ "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=",
64
+ "owner": "numtide",
65
+ "repo": "flake-utils",
66
+ "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a",
67
+ "type": "github"
68
+ },
69
+ "original": {
70
+ "owner": "numtide",
71
+ "repo": "flake-utils",
72
+ "type": "github"
73
+ }
74
+ },
75
+ "nixpkgs": {
76
+ "locked": {
77
+ "lastModified": 1704161960,
78
+ "narHash": "sha256-QGua89Pmq+FBAro8NriTuoO/wNaUtugt29/qqA8zeeM=",
79
+ "owner": "NixOS",
80
+ "repo": "nixpkgs",
81
+ "rev": "63143ac2c9186be6d9da6035fa22620018c85932",
82
+ "type": "github"
83
+ },
84
+ "original": {
85
+ "owner": "NixOS",
86
+ "ref": "nixpkgs-unstable",
87
+ "repo": "nixpkgs",
88
+ "type": "github"
89
+ }
90
+ },
91
+ "nixpkgs_2": {
92
+ "locked": {
93
+ "lastModified": 1728715894,
94
+ "narHash": "sha256-jupal4CmCQFKcQbqSkquDF6vYC0/SwqqhEFA9F1E4Uc=",
95
+ "owner": "nixos",
96
+ "repo": "nixpkgs",
97
+ "rev": "f152a2d1eb61baf0af9391d3e54af3e10b88e539",
98
+ "type": "github"
99
+ },
100
+ "original": {
101
+ "owner": "nixos",
102
+ "ref": "master",
103
+ "repo": "nixpkgs",
104
+ "type": "github"
105
+ }
106
+ },
107
+ "root": {
108
+ "inputs": {
109
+ "devshell": "devshell",
110
+ "flake-compat": "flake-compat",
111
+ "flake-utils": "flake-utils_2",
112
+ "nixpkgs": "nixpkgs_2"
113
+ }
114
+ },
115
+ "systems": {
116
+ "locked": {
117
+ "lastModified": 1681028828,
118
+ "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
119
+ "owner": "nix-systems",
120
+ "repo": "default",
121
+ "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
122
+ "type": "github"
123
+ },
124
+ "original": {
125
+ "owner": "nix-systems",
126
+ "repo": "default",
127
+ "type": "github"
128
+ }
129
+ },
130
+ "systems_2": {
131
+ "locked": {
132
+ "lastModified": 1681028828,
133
+ "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
134
+ "owner": "nix-systems",
135
+ "repo": "default",
136
+ "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
137
+ "type": "github"
138
+ },
139
+ "original": {
140
+ "owner": "nix-systems",
141
+ "repo": "default",
142
+ "type": "github"
143
+ }
144
+ }
145
+ },
146
+ "root": "root",
147
+ "version": 7
148
+ }
data/flake.nix ADDED
@@ -0,0 +1,103 @@
1
+ {
2
+ description = "Ruby Dev Env";
3
+ inputs = {
4
+ nixpkgs.url = "github:nixos/nixpkgs/master";
5
+ flake-utils.url = "github:numtide/flake-utils";
6
+ devshell.url = "github:numtide/devshell/main";
7
+ flake-compat = {
8
+ url = "github:edolstra/flake-compat";
9
+ flake = false;
10
+ };
11
+ };
12
+ outputs =
13
+ { self
14
+ , nixpkgs
15
+ , flake-utils
16
+ , devshell
17
+ , flake-compat
18
+ , ...
19
+ }:
20
+ flake-utils.lib.eachDefaultSystem (system:
21
+ let
22
+ cwd = builtins.toString ./.;
23
+ overlays = map (x: x.overlays.default) [
24
+ devshell
25
+ ];
26
+ pkgs = import nixpkgs { inherit system overlays; };
27
+ in
28
+ rec {
29
+
30
+ # nix develop
31
+ devShell = pkgs.devshell.mkShell {
32
+ env = [
33
+ ];
34
+ commands = [
35
+ {
36
+ name = "irb";
37
+ command = "bundle exec irb \"$@\"";
38
+ help = "Run console IRB (has completion menu)";
39
+ category = "Ruby";
40
+ }
41
+ {
42
+ name = "console";
43
+ command = "bundle exec irb \"$@\"";
44
+ help = "Run console IRB (has completion menu)";
45
+ category = "Ruby";
46
+ }
47
+ {
48
+ name = "pry";
49
+ command = "bundle exec pry \"$@\"";
50
+ help = "Run pry";
51
+ category = "Ruby";
52
+ }
53
+ {
54
+ name = "release";
55
+ command = "bundle exec rake release \"$@\"";
56
+ help = "Run rake release, which adds a tag and pushes to RubyGems";
57
+ category = "Ruby";
58
+ }
59
+ {
60
+ name = "rubocop";
61
+ command = "bundle exec rubocop \"$@\"";
62
+ help = "Run rubocop";
63
+ category = "Ruby";
64
+ }
65
+ {
66
+ name = "lint";
67
+ command = "bundle exec rubocop \"$@\"";
68
+ help = "Run rubocop";
69
+ category = "Ruby";
70
+ }
71
+ {
72
+ name = "rspec";
73
+ command = "bundle exec rspec \"$@\"";
74
+ help = "Run test suite";
75
+ category = "Ruby";
76
+ }
77
+ {
78
+ name = "update-flakes";
79
+ command = "make update-flakes \"$@\"";
80
+ help = "Update all flakes";
81
+ category = "Nix";
82
+ }
83
+ ];
84
+ packages = with pkgs; [
85
+ bash
86
+ curl
87
+ fd
88
+ fzf
89
+ gnused
90
+ jq
91
+ nodejs
92
+ # rubocop
93
+ # ruby
94
+ # rubyfmt # Broken
95
+ rubyPackages.ruby-lsp
96
+ rubyPackages.solargraph
97
+ rubyPackages.sorbet-runtime
98
+ ripgrep
99
+ wget
100
+ ];
101
+ };
102
+ });
103
+ }
@@ -0,0 +1,5 @@
1
+ module Paneron
2
+ module Register
3
+ class Error < StandardError; end
4
+ end
5
+ end
@@ -0,0 +1,51 @@
1
+ require "yaml"
2
+
3
+ module Paneron
4
+ 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
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,73 @@
1
+ require "yaml"
2
+
3
+ module Paneron
4
+ 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
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,79 @@
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
@@ -0,0 +1,5 @@
1
+ module Paneron
2
+ module Register
3
+ VERSION = "0.1.0".freeze
4
+ end
5
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "paneron/register/version"
4
+ require "paneron/register/error"
5
+ require "paneron/register/register"
6
+ require "paneron/register/register_root"
7
+ require "paneron/register/item_class"
8
+
9
+ # Paneron::Register module
10
+ module Paneron
11
+ module Register; end
12
+ end
data/lib/paneron.rb ADDED
@@ -0,0 +1 @@
1
+ module Paneron; end
@@ -0,0 +1,38 @@
1
+ lib = File.expand_path("lib", __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "paneron/register/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "paneron-register"
7
+ spec.version = Paneron::Register::VERSION
8
+ spec.authors = ["Ribose Inc."]
9
+ spec.email = ["open.source@ribose.com"]
10
+
11
+ spec.summary = "Access register data from Paneron"
12
+ spec.description = "Library to access register data from Paneron."
13
+ spec.homepage = "https://github.com/paneron/ruby-paneron-register"
14
+ spec.license = "BSD-2-Clause"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features|bin|.github)/}) \
18
+ || f.match(%r{Rakefile|bin/rspec})
19
+ end
20
+ spec.extra_rdoc_files = %w[README.adoc CHANGELOG.adoc LICENSE.txt]
21
+ spec.bindir = "bin"
22
+ # spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ["lib"]
24
+ spec.required_ruby_version = ">= 3.1.0"
25
+
26
+ # spec.add_runtime_dependency "yaml"
27
+
28
+ spec.add_development_dependency "debug"
29
+ spec.add_development_dependency "pry"
30
+ spec.add_development_dependency "rake", "~> 13.0"
31
+ spec.add_development_dependency "rspec", "~> 3.0"
32
+ spec.add_development_dependency "rspec-command", "~> 1.0"
33
+ spec.add_development_dependency "rubocop", "~> 1.67.0"
34
+ spec.add_development_dependency "rubocop-performance", "~> 1.22.1"
35
+ spec.add_development_dependency "rubocop-rake", "~> 0.6.0"
36
+ spec.add_development_dependency "rubocop-rspec", "~> 3.1.0"
37
+ spec.add_development_dependency "simplecov", "~> 0.15"
38
+ end
metadata ADDED
@@ -0,0 +1,210 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: paneron-register
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ribose Inc.
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2024-10-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: debug
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '13.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '13.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec-command
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 1.67.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 1.67.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop-performance
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 1.22.1
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 1.22.1
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop-rake
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 0.6.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.6.0
125
+ - !ruby/object:Gem::Dependency
126
+ name: rubocop-rspec
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: 3.1.0
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: 3.1.0
139
+ - !ruby/object:Gem::Dependency
140
+ name: simplecov
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '0.15'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '0.15'
153
+ description: Library to access register data from Paneron.
154
+ email:
155
+ - open.source@ribose.com
156
+ executables: []
157
+ extensions: []
158
+ extra_rdoc_files:
159
+ - README.adoc
160
+ - CHANGELOG.adoc
161
+ - LICENSE.txt
162
+ files:
163
+ - ".editorconfig"
164
+ - ".envrc"
165
+ - ".gitattributes"
166
+ - ".gitignore"
167
+ - ".hound.yml"
168
+ - ".irbrc"
169
+ - ".pryrc"
170
+ - ".rspec"
171
+ - ".rubocop.yml"
172
+ - CHANGELOG.adoc
173
+ - Gemfile
174
+ - LICENSE.txt
175
+ - Makefile
176
+ - README.adoc
177
+ - flake.lock
178
+ - flake.nix
179
+ - lib/paneron.rb
180
+ - lib/paneron/register.rb
181
+ - lib/paneron/register/error.rb
182
+ - lib/paneron/register/item_class.rb
183
+ - lib/paneron/register/register.rb
184
+ - lib/paneron/register/register_root.rb
185
+ - lib/paneron/register/version.rb
186
+ - paneron-register.gemspec
187
+ homepage: https://github.com/paneron/ruby-paneron-register
188
+ licenses:
189
+ - BSD-2-Clause
190
+ metadata: {}
191
+ post_install_message:
192
+ rdoc_options: []
193
+ require_paths:
194
+ - lib
195
+ required_ruby_version: !ruby/object:Gem::Requirement
196
+ requirements:
197
+ - - ">="
198
+ - !ruby/object:Gem::Version
199
+ version: 3.1.0
200
+ required_rubygems_version: !ruby/object:Gem::Requirement
201
+ requirements:
202
+ - - ">="
203
+ - !ruby/object:Gem::Version
204
+ version: '0'
205
+ requirements: []
206
+ rubygems_version: 3.3.7
207
+ signing_key:
208
+ specification_version: 4
209
+ summary: Access register data from Paneron
210
+ test_files: []