diff --git a/hyde.rb b/hyde.rb index 1937b93..59a3f40 100644 --- a/hyde.rb +++ b/hyde.rb @@ -1,33 +1,111 @@ module Hyde - class Servlet - def initialize (path, &block_optional) - + # Interchangeable pattern matching + module PatternMatching + def prep_path(path) + raise Exception, "Not permitted" if @lock_methods + @path = normalize(path) if path.kind_of? String + @path = path if path.kind_of? Regexp + end + def match?(path) + raise Exception, "Not permitted" if @lock_methods + split_path = path.split("/") + puts "#{path}, #{@path}, #{normalize_input(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) + else + return split_path[0] == @path + end + end + def normalize_input(path) + raise Exception, "Not permitted" if @lock_methods + (path.split "/").filter { |x| x != "" }.join("/") + end + def normalize(path) + raise Exception, "Not permitted" if @lock_methods + # remove multiple slashes in one spot + path = (path.split "/").filter {|x| x != ""}.join("/") + # globbing behaviour simulated with regexp + if path.match /(?