Fix regexes in CaskLoader
.
This commit is contained in:
parent
b568179222
commit
cbd9715e5b
@ -3,6 +3,18 @@ module Hbc
|
|||||||
class FromContentLoader
|
class FromContentLoader
|
||||||
attr_reader :content
|
attr_reader :content
|
||||||
|
|
||||||
|
def self.can_load?(ref)
|
||||||
|
return false unless ref.respond_to?(:to_str)
|
||||||
|
content = ref.to_str
|
||||||
|
|
||||||
|
token = /(?:"[^"]*"|'[^']*')/
|
||||||
|
curly = /\(\s*#{token}\s*\)\s*\{.*\}/
|
||||||
|
do_end = /\s+#{token}\s+do(?:\s*;\s*|\s+).*end/
|
||||||
|
regex = /\A\s*cask(?:#{curly.source}|#{do_end.source})\s*\Z/m
|
||||||
|
|
||||||
|
content.match?(regex)
|
||||||
|
end
|
||||||
|
|
||||||
def initialize(content)
|
def initialize(content)
|
||||||
@content = content
|
@content = content
|
||||||
end
|
end
|
||||||
@ -56,7 +68,8 @@ module Hbc
|
|||||||
|
|
||||||
class FromURILoader < FromPathLoader
|
class FromURILoader < FromPathLoader
|
||||||
def self.can_load?(ref)
|
def self.can_load?(ref)
|
||||||
ref.to_s.match?(::URI::DEFAULT_PARSER.make_regexp)
|
uri_regex = ::URI::DEFAULT_PARSER.make_regexp
|
||||||
|
ref.to_s.match?(Regexp.new('\A' + uri_regex.source + '\Z', uri_regex.options))
|
||||||
end
|
end
|
||||||
|
|
||||||
attr_reader :url
|
attr_reader :url
|
||||||
@ -156,15 +169,9 @@ module Hbc
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.for(ref)
|
def self.for(ref)
|
||||||
if ref.respond_to?(:to_str)
|
|
||||||
content = ref.to_str
|
|
||||||
if content.match?(/\A\s*cask\s+(?:"[^"]*"|'[^']*')\s+do(?:\s+.*\s+|;?\s+)end\s*\Z/)
|
|
||||||
return FromContentLoader.new(content)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
[
|
[
|
||||||
FromInstanceLoader,
|
FromInstanceLoader,
|
||||||
|
FromContentLoader,
|
||||||
FromURILoader,
|
FromURILoader,
|
||||||
FromTapLoader,
|
FromTapLoader,
|
||||||
FromTapPathLoader,
|
FromTapPathLoader,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user