2023-09-29 14:13:00 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'forwardable'
|
|
|
|
require 'json'
|
|
|
|
require 'open3'
|
|
|
|
require 'pathname'
|
|
|
|
|
|
|
|
require_relative 'referator/config'
|
2023-09-30 10:10:31 -04:00
|
|
|
require_relative 'referator/config/categories'
|
2023-09-29 14:13:00 -04:00
|
|
|
require_relative 'referator/config/formats'
|
|
|
|
require_relative 'referator/config/repo'
|
2023-09-30 16:21:01 -04:00
|
|
|
require_relative 'referator/config/scripts'
|
2023-09-29 14:13:00 -04:00
|
|
|
require_relative 'referator/footnotes'
|
|
|
|
require_relative 'referator/note'
|
|
|
|
require_relative 'referator/reference'
|
|
|
|
require_relative 'referator/script'
|
|
|
|
|
|
|
|
module Referator
|
|
|
|
NAME_RE = /\A\w+(_\w+)*\z/
|
|
|
|
SLUG_RE = /\A\w+(-\w+)*\z/
|
2023-09-30 15:59:59 -04:00
|
|
|
|
2023-09-30 16:11:32 -04:00
|
|
|
SCRIPT_ENUMS = %i[format template].sort.freeze
|
2023-09-30 17:32:24 -04:00
|
|
|
SCRIPT_OBJS = %i[note notes].sort.freeze
|
2023-09-30 16:11:32 -04:00
|
|
|
SCRIPT_VARS = [*SCRIPT_ENUMS, *SCRIPT_OBJS].sort.freeze
|
|
|
|
|
2023-09-30 15:59:59 -04:00
|
|
|
def self.validate_name!(name)
|
|
|
|
name.freeze
|
|
|
|
unless name.instance_of? Symbol
|
|
|
|
raise TypeError, "Expected #{Symbol}, got #{name.class}"
|
|
|
|
end
|
|
|
|
raise 'Invalid name' unless NAME_RE.match? name
|
|
|
|
|
|
|
|
name
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.validate_slug!(slug)
|
|
|
|
slug.freeze
|
|
|
|
unless slug.instance_of? String
|
|
|
|
raise TypeError, "Expected #{String}, got #{slug.class}"
|
|
|
|
end
|
|
|
|
raise 'Invalid slug' unless SLUG_RE.match? slug
|
|
|
|
|
|
|
|
slug
|
|
|
|
end
|
2023-09-30 16:11:32 -04:00
|
|
|
|
|
|
|
def self.validate_script_var!(var)
|
|
|
|
var.freeze
|
|
|
|
unless var.instance_of? Symbol
|
|
|
|
raise TypeError, "Expected #{String}, got #{slug.class}"
|
|
|
|
end
|
|
|
|
raise 'Invalid var' unless SCRIPT_VARS.include? var
|
|
|
|
|
|
|
|
var
|
|
|
|
end
|
2023-09-29 14:13:00 -04:00
|
|
|
end
|