-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
54 changed files
with
332 additions
and
321 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
require "paneron_registry" | ||
require "paneron/register" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
require "paneron_registry" | ||
require "paneron/register" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module Paneron; end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module Paneron | ||
module Register | ||
class Error < StandardError; end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.