paneron_registry 0.0.2

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: c95d593efcfd4bbb3b68b1109adec30a40bbe0b4e62fca236c15abee6d2f7aa8
4
+ data.tar.gz: 621cc3cf276bc2aa5726c0e335a15496e697f5931365b3e51114f47a83f85efc
5
+ SHA512:
6
+ metadata.gz: ba345feb7b1caf2c5c60755d2bd4a98bd63990a08a0e5df44964abc19efbc2ab100bd80345ba97210a17603bc57b25935a55622d2276af29126993a4f98455e9
7
+ data.tar.gz: cea1012192274c0e7d7d40dc892f8bf32682aa0888f0b0b5e247b244c71cd9a5895084df9eff480c10cdf5a7462b44fba71243f2665ce1005a1f0d7585735dc2
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/.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 Registry Ruby Gem
2
+
3
+ image:https://img.shields.io/gem/v/paneron_registry.svg["Gem Version", link="https://rubygems.org/gems/paneron_registry"]
4
+ image:https://github.com/paneron/ruby-paneron_registry/actions/workflows/test.yaml/badge.svg["Build Status",Link="https://github.com/paneron/ruby-paneron_registry/actions/workflows/test.yaml"]
5
+ image:https://codeclimate.com/github/paneron/ruby-paneron_registry/badges/gpa.svg["Code Climate", link="https://codeclimate.com/github/paneron/ruby-paneron_registry"]
6
+ image:https://img.shields.io/github/issues-pr-raw/paneron/ruby-paneron_registry.svg["Pull Requests", link="https://github.com/paneron/ruby-paneron_registry/pulls"]
7
+ image:https://img.shields.io/github/commits-since/paneron/ruby-paneron_registry/latest.svg["Commits since latest",link="https://github.com/paneron/ruby-paneron_registry/releases"]
8
+
9
+
10
+ == Installation
11
+
12
+ ```sh
13
+ gem install paneron_registry
14
+ ```
15
+
16
+ == Usage
17
+
18
+ ```ruby
19
+ require "paneron_registry"
20
+
21
+ # Initialize a new registry
22
+ # This example uses a working copy of Paneron's registry.
23
+ registry = PaneronRegistry::Registry.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 registry root:
29
+ root = PaneronRegistry::RegistryRoot.new(
30
+ "/Users/username/Library/Application Support/Electron/working_copies/00000000-0001-0000-0000-000000000001",
31
+ )
32
+ registry = 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,79 @@
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 = "rubocop";
37
+ command = "bundle exec rubocop \"$@\"";
38
+ help = "Run rubocop";
39
+ category = "Ruby";
40
+ }
41
+ {
42
+ name = "lint";
43
+ command = "bundle exec rubocop \"$@\"";
44
+ help = "Run rubocop";
45
+ category = "Ruby";
46
+ }
47
+ {
48
+ name = "rspec";
49
+ command = "bundle exec rspec \"$@\"";
50
+ help = "Run test suite";
51
+ category = "Ruby";
52
+ }
53
+ {
54
+ name = "update-flakes";
55
+ command = "make update-flakes \"$@\"";
56
+ help = "Update all flakes";
57
+ category = "Nix";
58
+ }
59
+ ];
60
+ packages = with pkgs; [
61
+ bash
62
+ curl
63
+ fd
64
+ fzf
65
+ gnused
66
+ jq
67
+ nodejs
68
+ # rubocop
69
+ # ruby
70
+ # rubyfmt # Broken
71
+ rubyPackages.ruby-lsp
72
+ rubyPackages.solargraph
73
+ rubyPackages.sorbet-runtime
74
+ ripgrep
75
+ wget
76
+ ];
77
+ };
78
+ });
79
+ }
@@ -0,0 +1,4 @@
1
+ module PaneronRegistry
2
+ class Error < StandardError
3
+ end
4
+ end
@@ -0,0 +1,48 @@
1
+ require "yaml"
2
+
3
+ module PaneronRegistry
4
+ class ItemClass
5
+ attr_reader :registry_path, :registry_root_path, :registry_yaml_path,
6
+ :item_class_name, :item_class_path, :registry_name
7
+
8
+ def initialize(registry_root_path, registry_name, item_class_name)
9
+ File.join(registry_root_path, registry_name)
10
+ item_class_path = File.join(registry_root_path, registry_name,
11
+ item_class_name)
12
+ self.class.validate_item_class_path(item_class_path)
13
+ @item_class_path = item_class_path
14
+ @items_uuids = nil
15
+ @items = {}
16
+ end
17
+
18
+ def self.validate_item_class_path(path)
19
+ unless File.exist?(path)
20
+ raise PaneronRegistry::Error,
21
+ "Item class path does not exist"
22
+ end
23
+ unless File.directory?(path)
24
+ raise PaneronRegistry::Error,
25
+ "Item class path is not a directory"
26
+ end
27
+ end
28
+
29
+ def item_uuids
30
+ @item_uuids ||= Dir.glob(File.join(item_class_path, "*.yaml"))
31
+ .map { |file| File.basename(file, ".yaml") }
32
+ end
33
+
34
+ def item_yamls(uuid = nil)
35
+ if uuid.nil?
36
+ item_uuids.map do |uuid|
37
+ item_yamls(uuid)
38
+ end
39
+ else
40
+ @items[uuid] ||=
41
+ YAML.safe_load_file(
42
+ File.join(item_class_path, "#{uuid}.yaml"),
43
+ permitted_classes: [Time],
44
+ )
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,70 @@
1
+ require "yaml"
2
+
3
+ module PaneronRegistry
4
+ class Registry
5
+ attr_reader :registry_path, :registry_root_path, :registry_yaml_path,
6
+ :registry_name
7
+
8
+ def initialize(registry_root_path, registry_name)
9
+ registry_path = File.join(registry_root_path, registry_name)
10
+ self.class.validate_registry_path(registry_path)
11
+ @registry_name = registry_name
12
+ @registry_root_path = registry_root_path
13
+ @registry_path = registry_path
14
+ @registry_yaml_path = File.join(registry_path,
15
+ REGISTER_METADATA_FILENAME)
16
+ @item_classes = {}
17
+ @item_class_names = nil
18
+ @item_uuids = nil
19
+ end
20
+
21
+ REGISTER_METADATA_FILENAME = "/register.yaml".freeze
22
+
23
+ def self.validate_registry_path(registry_path)
24
+ unless File.exist?(registry_path)
25
+ raise PaneronRegistry::Error,
26
+ "Registry path does not exist"
27
+ end
28
+ unless File.directory?(registry_path)
29
+ raise PaneronRegistry::Error,
30
+ "Registry path is not a directory"
31
+ end
32
+ unless File.exist?(File.join(
33
+ registry_path, REGISTER_METADATA_FILENAME
34
+ ))
35
+ raise PaneronRegistry::Error,
36
+ "Registry metadata file does not exist"
37
+ end
38
+ end
39
+
40
+ def item_classes(item_class_name = nil)
41
+ if item_class_name.nil?
42
+ item_class_names.map do |item_class_name|
43
+ item_classes(item_class_name)
44
+ end
45
+ else
46
+ @item_classes[item_class_name] ||=
47
+ PaneronRegistry::ItemClass.new(
48
+ registry_root_path, registry_name, item_class_name
49
+ )
50
+ end
51
+ end
52
+
53
+ def item_class_names
54
+ @item_class_names ||=
55
+ Dir.glob(File.join(registry_path, "*/*.yaml"))
56
+ .map { |file| File.basename(File.dirname(file)) }.uniq
57
+ end
58
+
59
+ def item_uuids
60
+ item_classes.map(&:item_uuids).flatten
61
+ end
62
+
63
+ def get_metadata_yaml
64
+ YAML.safe_load_file(
65
+ registry_yaml_path,
66
+ permitted_classes: [Time],
67
+ )
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,76 @@
1
+ require "yaml"
2
+
3
+ module PaneronRegistry
4
+ class RegistryRoot
5
+ attr_reader :registry_root_path, :registry_root_yaml_path
6
+
7
+ def initialize(registry_root_path)
8
+ self.class.validate_root_path(registry_root_path)
9
+ @registry_root_path = registry_root_path
10
+ @registry_root_yaml_path = File.join(registry_root_path,
11
+ REGISTER_ROOT_METADATA_FILENAME)
12
+ @registry_names = nil
13
+ @registries = {}
14
+ end
15
+
16
+ REGISTER_ROOT_METADATA_FILENAME = "/paneron.yaml".freeze
17
+
18
+ def self.validate_root_path(registry_root_path)
19
+ unless File.exist?(registry_root_path)
20
+ raise PaneronRegistry::Error,
21
+ "Registry root path does not exist"
22
+ end
23
+ unless File.directory?(registry_root_path)
24
+ raise PaneronRegistry::Error,
25
+ "Registry root path is not a directory"
26
+ end
27
+ unless File.exist?(File.join(
28
+ registry_root_path, REGISTER_ROOT_METADATA_FILENAME
29
+ ))
30
+ raise PaneronRegistry::Error,
31
+ "Registry root metadata file does not exist"
32
+ end
33
+ end
34
+
35
+ def registry_names
36
+ @registry_names ||= Dir.glob(
37
+ File.join(
38
+ registry_root_path,
39
+ "*#{PaneronRegistry::Registry::REGISTER_METADATA_FILENAME}",
40
+ ),
41
+ )
42
+ .map do |file|
43
+ File.basename(File.dirname(file))
44
+ end
45
+ end
46
+
47
+ def registry_path(registry_name)
48
+ File.join(registry_root_path, registry_name)
49
+ end
50
+
51
+ def get_root_metadata
52
+ YAML.safe_load_file(registry_root_yaml_path)
53
+ end
54
+
55
+ def registries(registry_name = nil)
56
+ if registry_name.nil?
57
+ registry_names.map do |registry_name|
58
+ registries(registry_name)
59
+ end
60
+ else
61
+ @registries[registry_name] ||=
62
+ PaneronRegistry::Registry.new(registry_root_path,
63
+ registry_name)
64
+ end
65
+ end
66
+
67
+ def registry_metadata_yaml(registry_name)
68
+ registires(registry_name).get_metadata_yaml
69
+
70
+ YAML.safe_load_file(
71
+ registry_yaml_path(registry_name),
72
+ permitted_classes: [Time],
73
+ )
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,3 @@
1
+ module PaneronRegistry
2
+ VERSION = "0.0.2".freeze
3
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "paneron_registry/version"
4
+ require "paneron_registry/error"
5
+ require "paneron_registry/registry"
6
+ require "paneron_registry/registry_root"
7
+ require "paneron_registry/item_class"
8
+
9
+ # PaneronRegistry module
10
+ module PaneronRegistry
11
+ 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_registry/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "paneron_registry"
7
+ spec.version = PaneronRegistry::VERSION
8
+ spec.authors = ["Ribose Inc."]
9
+ spec.email = ["open.source@ribose.com"]
10
+
11
+ spec.summary = "Access registry data from Paneron"
12
+ spec.description = "Library to access registry data from Paneron."
13
+ spec.homepage = "https://github.com/paneron/ruby-paneron_registry"
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,207 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: paneron_registry
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
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 registry 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
+ - ".rspec"
169
+ - ".rubocop.yml"
170
+ - CHANGELOG.adoc
171
+ - Gemfile
172
+ - LICENSE.txt
173
+ - Makefile
174
+ - README.adoc
175
+ - flake.lock
176
+ - flake.nix
177
+ - lib/paneron_registry.rb
178
+ - lib/paneron_registry/error.rb
179
+ - lib/paneron_registry/item_class.rb
180
+ - lib/paneron_registry/registry.rb
181
+ - lib/paneron_registry/registry_root.rb
182
+ - lib/paneron_registry/version.rb
183
+ - paneron_registry.gemspec
184
+ homepage: https://github.com/paneron/ruby-paneron_registry
185
+ licenses:
186
+ - BSD-2-Clause
187
+ metadata: {}
188
+ post_install_message:
189
+ rdoc_options: []
190
+ require_paths:
191
+ - lib
192
+ required_ruby_version: !ruby/object:Gem::Requirement
193
+ requirements:
194
+ - - ">="
195
+ - !ruby/object:Gem::Version
196
+ version: 3.1.0
197
+ required_rubygems_version: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - ">="
200
+ - !ruby/object:Gem::Version
201
+ version: '0'
202
+ requirements: []
203
+ rubygems_version: 3.3.7
204
+ signing_key:
205
+ specification_version: 4
206
+ summary: Access registry data from Paneron
207
+ test_files: []