referator/lib/referator.rb
2023-10-01 00:12:59 +04:00

54 lines
1.3 KiB
Ruby

# frozen_string_literal: true
require 'forwardable'
require 'json'
require 'open3'
require 'pathname'
require_relative 'referator/config'
require_relative 'referator/config/categories'
require_relative 'referator/config/formats'
require_relative 'referator/config/repo'
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/
SCRIPT_ENUMS = %i[format template].sort.freeze
SCRIPT_OBJS = %i[notes].sort.freeze
SCRIPT_VARS = [*SCRIPT_ENUMS, *SCRIPT_OBJS].sort.freeze
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
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
end