Validate script vars
This commit is contained in:
parent
b0c7de3aae
commit
b83e340dbe
2 changed files with 15 additions and 3 deletions
|
@ -18,6 +18,10 @@ 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
|
||||
|
@ -37,4 +41,14 @@ module Referator
|
|||
|
||||
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
|
||||
|
|
|
@ -105,9 +105,7 @@ module Referator
|
|||
|
||||
def vars=(vars)
|
||||
@vars = [*vars].uniq.sort.freeze.each do |var|
|
||||
unless var.instance_of? Symbol
|
||||
raise TypeError, "Expected #{Symbol}, got #{var.class}"
|
||||
end
|
||||
Referator.validate_script_var! var
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue