Pathspec functions correctly
This commit is contained in:
parent
b006e0f672
commit
d8cddf7479
24
hyde.rb
24
hyde.rb
|
@ -8,14 +8,16 @@ module Hyde
|
|||
end
|
||||
def match?(path)
|
||||
raise Exception, "Not permitted" if @lock_methods
|
||||
split_path = path.split("/")
|
||||
puts "#{path}, #{@path}, #{normalize_input(path)}"
|
||||
return true if @path == ""
|
||||
if @path.kind_of? Regexp then
|
||||
anchored_regex = Regexp.new("^"+@path.to_s+"$")
|
||||
return anchored_regex.match split_path[0] unless @full_regexp
|
||||
return anchored_regex.match normalize_input(path)
|
||||
return Regexp.new("^"+@path.to_s+"$").match normalize_input(path)
|
||||
else
|
||||
return split_path[0] == @path
|
||||
split_path = path.split("/").filter { |x| x != "" }
|
||||
@path.split("/").filter { |x| x != "" }
|
||||
.each_with_index { |x,i|
|
||||
return false if x != split_path[i]
|
||||
}
|
||||
return true
|
||||
end
|
||||
end
|
||||
def normalize_input(path)
|
||||
|
@ -24,8 +26,8 @@ module Hyde
|
|||
end
|
||||
def normalize(path)
|
||||
raise Exception, "Not permitted" if @lock_methods
|
||||
# remove multiple slashes in one spot
|
||||
path = (path.split "/").filter {|x| x != ""}.join("/")
|
||||
# remove multiple slashes in one spot and trim edge slashes
|
||||
path = normalize_input(path)
|
||||
# globbing behaviour simulated with regexp
|
||||
if path.match /(?<!\\)[\*\?\[]/ then
|
||||
path = Regexp.new(path
|
||||
|
@ -50,7 +52,6 @@ module Hyde
|
|||
@lock_methods = false
|
||||
end
|
||||
def match(path)
|
||||
puts (match? path)
|
||||
if match? path then
|
||||
exec if defined? exec
|
||||
end
|
||||
|
@ -58,7 +59,6 @@ module Hyde
|
|||
end
|
||||
class PrintProbe < Hyde::Probe
|
||||
def match(path)
|
||||
puts (match? path)
|
||||
if match? path then
|
||||
puts "#{path} matched!"
|
||||
end
|
||||
|
@ -78,13 +78,12 @@ module Hyde
|
|||
class Pathspec
|
||||
include Hyde::PatternMatching
|
||||
include Hyde::Handlers
|
||||
def initialize (path, root_path: nil, full_regexp: false, &block)
|
||||
def initialize (path, root_path: nil, &block)
|
||||
prep_path path
|
||||
@chain = []
|
||||
@root_override = root_path
|
||||
@remap = false
|
||||
@lock_methods = true
|
||||
@full_regexp = full_regexp
|
||||
self.instance_eval &block
|
||||
@lock_methods = false
|
||||
end
|
||||
|
@ -103,7 +102,6 @@ module Hyde
|
|||
if match? path then
|
||||
cut_path = normalize_input(path).sub(@path, "")
|
||||
next_pathspec = @chain.find { |x| x.match? cut_path }
|
||||
puts next_pathspec.inspect
|
||||
next_pathspec.match cut_path if next_pathspec
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue