2023-09-29 14:13:00 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'forwardable'
|
|
|
|
require 'json'
|
|
|
|
require 'open3'
|
|
|
|
require 'pathname'
|
|
|
|
|
2023-10-02 06:04:44 -04:00
|
|
|
require_relative 'referator/command'
|
2023-09-29 14:13:00 -04:00
|
|
|
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/repo'
|
|
|
|
require_relative 'referator/footnotes'
|
2023-10-23 13:08:23 -04:00
|
|
|
require_relative 'referator/machine'
|
2023-09-29 14:13:00 -04:00
|
|
|
require_relative 'referator/note'
|
|
|
|
require_relative 'referator/reference'
|
|
|
|
|
|
|
|
module Referator
|
|
|
|
NAME_RE = /\A\w+(_\w+)*\z/
|
|
|
|
SLUG_RE = /\A\w+(-\w+)*\z/
|
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-29 14:13:00 -04:00
|
|
|
end
|