lib/hx/path.rb in hx-0.24.0 vs lib/hx/path.rb in hx-0.25.0
- old
+ new
@@ -27,10 +27,14 @@
module Selector
def accept_path?(path)
raise NotImplementedError, "#{self.class}#accept_path? not implemented"
end
+ def literal?
+ false
+ end
+
def |(other)
Disjunction.build(self, other)
end
def &(other)
@@ -59,16 +63,21 @@
class Pattern
include Selector
def initialize(tokens)
+ @is_literal = tokens.size == 1 and String === tokens.first
@regexp = Regexp.new("^#{tokens.map { |token|
case token
when :doublestar; '.*'
when :star; '[^/]*'
else; Regexp.quote(token)
end
}}$")
+ end
+
+ def literal?
+ @is_literal
end
def accept_path?(path) ; !!(path =~ @regexp) ; end
end