Make a constant for long inline regexp (#7810)

This commit is contained in:
Eryk Napierała 2020-05-13 14:26:46 +02:00 committed by GitHub
parent f2f90e98b3
commit 792721d7bc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,5 +1,6 @@
class CodesandboxTag < LiquidTagBase
PARTIAL = "liquids/codesandbox".freeze
OPTIONS_REGEXP = /\A(initialpath=([a-zA-Z0-9\-\_\/\.\@\%])+)\Z|\A(module=([a-zA-Z0-9\-\_\/\.\@\%])+)\Z|\A(runonclick=((0|1){1}))\Z|\Aview=(editor|split|preview)\Z/.freeze
def initialize(tag_name, id, tokens)
super
@ -48,7 +49,7 @@ class CodesandboxTag < LiquidTagBase
# composed of letters, numbers, dashes, underscores, forward slashes, @ signs, periods/dots,
# and % symbols. Invalid options will raise an exception
def valid_option(option)
raise StandardError, "CodeSandbox Error: Invalid options" unless (option =~ /\A(initialpath=([a-zA-Z0-9\-\_\/\.\@\%])+)\Z|\A(module=([a-zA-Z0-9\-\_\/\.\@\%])+)\Z|\A(runonclick=((0|1){1}))\Z|\Aview=(editor|split|preview)\Z/)&.zero?
raise StandardError, "CodeSandbox Error: Invalid options" unless (option =~ OPTIONS_REGEXP)&.zero?
option
end