referator/lib/referator.rb

40 lines
942 B
Ruby

# frozen_string_literal: true
require 'forwardable'
require 'json'
require 'open3'
require 'pathname'
require_relative 'referator/command'
require_relative 'referator/config'
require_relative 'referator/config/categories'
require_relative 'referator/config/repo'
require_relative 'referator/footnotes'
require_relative 'referator/machine'
require_relative 'referator/note'
require_relative 'referator/reference'
module Referator
NAME_RE = /\A\w+(_\w+)*\z/
SLUG_RE = /\A\w+(-\w+)*\z/
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
end