Skip to content

Commit

Permalink
chore: Rename to paneron-register
Browse files Browse the repository at this point in the history
Fixes #4
  • Loading branch information
ribose-jeffreylau committed Oct 17, 2024
1 parent 8bd2dec commit 21dc1ca
Show file tree
Hide file tree
Showing 54 changed files with 332 additions and 321 deletions.
2 changes: 1 addition & 1 deletion .irbrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
require "paneron_registry"
require "paneron/register"
2 changes: 1 addition & 1 deletion .pryrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
require "paneron_registry"
require "paneron/register"
28 changes: 14 additions & 14 deletions README.adoc
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
= Paneron Registry Ruby Gem
= Paneron Register Ruby Gem

image:https://img.shields.io/gem/v/paneron_registry.svg["Gem Version", link="https://rubygems.org/gems/paneron_registry"]
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"]
image:https://codeclimate.com/github/paneron/ruby-paneron_registry/badges/gpa.svg["Code Climate", link="https://codeclimate.com/github/paneron/ruby-paneron_registry"]
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"]
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"]
image:https://img.shields.io/gem/v/paneron-register.svg["Gem Version", link="https://rubygems.org/gems/paneron-register"]
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"]
image:https://codeclimate.com/github/paneron/ruby-paneron-register/badges/gpa.svg["Code Climate", link="https://codeclimate.com/github/paneron/ruby-paneron-register"]
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"]
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"]


== Installation

```sh
gem install paneron_registry
gem install paneron-register
```

== Usage

```ruby
require "paneron_registry"
require "paneron/register"

# Initialize a new registry
# This example uses a working copy of Paneron's registry.
registry = PaneronRegistry::Registry.new(
# Initialize a new register
# This example uses a working copy of Paneron's register.
register = Paneron::Register::Register.new(
"/Users/username/Library/Application Support/Electron/working_copies/00000000-0001-0000-0000-000000000001",
"register_name-1"
)

# Alternatively, initialize a new registry root:
root = PaneronRegistry::RegistryRoot.new(
# Alternatively, initialize a new register root:
root = Paneron::Register::RegisterRoot.new(
"/Users/username/Library/Application Support/Electron/working_copies/00000000-0001-0000-0000-000000000001",
)
registry = root.registries("register_name-1")
register = root.registries("register_name-1")

# Get all item class objects
register.item_classes
Expand Down
2 changes: 1 addition & 1 deletion bin/console
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# frozen_string_literal: true

require "bundler/setup"
require "paneron_registry"
require "paneron/register"

# You can add fixtures and/or initialization code here to make experimenting
# with your gem easier. You can also use a different console, if you like.
Expand Down
1 change: 1 addition & 0 deletions lib/paneron.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module Paneron; end
12 changes: 12 additions & 0 deletions lib/paneron/register.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

require "paneron/register/version"
require "paneron/register/error"
require "paneron/register/register"
require "paneron/register/register_root"
require "paneron/register/item_class"

# Paneron::Register module
module Paneron
module Register; end
end
5 changes: 5 additions & 0 deletions lib/paneron/register/error.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module Paneron
module Register
class Error < StandardError; end
end
end
51 changes: 51 additions & 0 deletions lib/paneron/register/item_class.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
require "yaml"

module Paneron
module Register
class ItemClass
attr_reader :register_path, :register_root_path, :register_yaml_path,
:item_class_name, :item_class_path, :register_name

def initialize(register_root_path, register_name, item_class_name)
File.join(register_root_path, register_name)
item_class_path = File.join(register_root_path, register_name,
item_class_name)
self.class.validate_item_class_path(item_class_path)
@item_class_path = item_class_path
@items_uuids = nil
@items = {}
end

def self.validate_item_class_path(path)
unless File.exist?(path)
raise Paneron::Register::Error,
"Item class path does not exist"
end
unless File.directory?(path)
raise Paneron::Register::Error,
"Item class path is not a directory"
end
end

def item_uuids
@item_uuids ||= Dir.glob(File.join(item_class_path, "*.yaml"))
.map { |file| File.basename(file, ".yaml") }
end

def item_yamls(uuid = nil)
if uuid.nil?
item_uuids.reduce({}) do |acc, uuid|
acc[uuid] = item_yamls(uuid)
acc
end
else
@items[uuid] ||=
YAML.safe_load_file(
File.join(item_class_path, "#{uuid}.yaml"),
permitted_classes: [Time],
)
end
end
end
end
end
73 changes: 73 additions & 0 deletions lib/paneron/register/register.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
require "yaml"

module Paneron
module Register
class Register
attr_reader :register_path, :register_root_path, :register_yaml_path,
:register_name

def initialize(register_root_path, register_name)
register_path = File.join(register_root_path, register_name)
self.class.validate_register_path(register_path)
@register_name = register_name
@register_root_path = register_root_path
@register_path = register_path
@register_yaml_path = File.join(register_path,
REGISTER_METADATA_FILENAME)
@item_classes = {}
@item_class_names = nil
@item_uuids = nil
end

REGISTER_METADATA_FILENAME = "/register.yaml".freeze

def self.validate_register_path(register_path)
unless File.exist?(register_path)
raise Paneron::Register::Error,
"Register path does not exist"
end
unless File.directory?(register_path)
raise Paneron::Register::Error,
"Register path is not a directory"
end
unless File.exist?(File.join(
register_path, REGISTER_METADATA_FILENAME
))
raise Paneron::Register::Error,
"Register metadata file does not exist"
end
end

def item_classes(item_class_name = nil)
if item_class_name.nil?
item_class_names.reduce({}) do |acc, item_class_name|
acc[item_class_name] = item_classes(item_class_name)
acc
end
else
@item_classes[item_class_name] ||=
Paneron::Register::ItemClass.new(
register_root_path, register_name, item_class_name
)
end
end

def item_class_names
@item_class_names ||=
Dir.glob(File.join(register_path, "*/*.yaml"))
.map { |file| File.basename(File.dirname(file)) }.uniq
end

def item_uuids
item_classes.values.map(&:item_uuids).flatten
end

def get_metadata_yaml
YAML.safe_load_file(
register_yaml_path,
permitted_classes: [Time],
)
end
end
end
end
79 changes: 79 additions & 0 deletions lib/paneron/register/register_root.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
require "yaml"

module Paneron
module Register
class RegisterRoot
attr_reader :register_root_path, :register_root_yaml_path

def initialize(register_root_path)
self.class.validate_root_path(register_root_path)
@register_root_path = register_root_path
@register_root_yaml_path = File.join(register_root_path,
REGISTER_ROOT_METADATA_FILENAME)
@register_names = nil
@registries = {}
end

REGISTER_ROOT_METADATA_FILENAME = "/paneron.yaml".freeze

def self.validate_root_path(register_root_path)
unless File.exist?(register_root_path)
raise Paneron::Register::Error,
"Register root path does not exist"
end
unless File.directory?(register_root_path)
raise Paneron::Register::Error,
"Register root path is not a directory"
end
unless File.exist?(File.join(
register_root_path, REGISTER_ROOT_METADATA_FILENAME
))
raise Paneron::Register::Error,
"Register root metadata file does not exist"
end
end

def register_names
@register_names ||= Dir.glob(
File.join(
register_root_path,
"*#{Paneron::Register::Register::REGISTER_METADATA_FILENAME}",
),
)
.map do |file|
File.basename(File.dirname(file))
end
end

def register_path(register_name)
File.join(register_root_path, register_name)
end

def get_root_metadata
YAML.safe_load_file(register_root_yaml_path)
end

def registries(register_name = nil)
if register_name.nil?
register_names.reduce({}) do |acc, register_name|
acc[register_name] = registries(register_name)
acc
end
else
@registries[register_name] ||=
Paneron::Register::Register.new(register_root_path,
register_name)
end
end

def register_metadata_yaml(register_name)
registires(register_name).get_metadata_yaml

YAML.safe_load_file(
register_yaml_path(register_name),
permitted_classes: [Time],
)
end
end
end
end
5 changes: 5 additions & 0 deletions lib/paneron/register/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module Paneron
module Register
VERSION = "0.0.3".freeze
end
end
11 changes: 0 additions & 11 deletions lib/paneron_registry.rb

This file was deleted.

4 changes: 0 additions & 4 deletions lib/paneron_registry/error.rb

This file was deleted.

49 changes: 0 additions & 49 deletions lib/paneron_registry/item_class.rb

This file was deleted.

Loading

0 comments on commit 21dc1ca

Please sign in to comment.