Permalink
Browse files

hide matches with logic

  • Loading branch information...
1 parent ad3feef commit c14f1067b0a4e2e4f0f8857d40b1a221104d6eef @joshbuddy committed Sep 7, 2011
Showing with 11 additions and 7 deletions.
  1. +10 −6 lib/http_router/route.rb
  2. +1 −1 lib/http_router/util.rb
View
16 lib/http_router/route.rb
@@ -1,6 +1,6 @@
class HttpRouter
class Route
- attr_reader :default_values, :router, :conditions, :original_path, :match_partially, :dest, :regex, :name, :matches_with, :dest, :significant_variable_names
+ attr_reader :default_values, :router, :conditions, :original_path, :match_partially, :dest, :regex, :name, :dest, :significant_variable_names
alias_method :match_partially?, :match_partially
alias_method :regex?, :regex
@@ -63,6 +63,10 @@ def to_s
"#<HttpRouter:Route #{object_id} @original_path=#{@original_path.inspect} @conditions=#{@conditions.inspect}>"
end
+ def matches_with(var_name)
+ @matches_with && @matches_with[:"#{var_name}"]
+ end
+
private
def url_with_params(*a)
url_args_processing(a) do |args, options|
@@ -133,7 +137,7 @@ def process_opts
def process_match_with
significant_variable_names.each do |name|
- (@matches_with ||= {})[name] = @opts.delete(name) if @opts.key?(name) && (@matches_with.nil? || !@matches_with.key?(name))
+ (@matches_with ||= {})[name] = @opts.delete(name) if @opts.key?(name) && !matches_with(name)
end
end
@@ -168,10 +172,10 @@ def add_normal_part(node, part, param_names)
node.add_lookup(part[1].chr)
when ?:
param_names << name.to_sym
- @matches_with && @matches_with[name.to_sym] ? node.add_spanning_match(@matches_with[name.to_sym]) : node.add_variable
+ matches_with(name) ? node.add_spanning_match(matches_with(name)) : node.add_variable
when ?*
param_names << name.to_sym
- @matches_with && @matches_with[name.to_sym] ? node.add_glob_regexp(@matches_with[name.to_sym]) : node.add_glob
+ matches_with(name) ? node.add_glob_regexp(matches_with(name)) : node.add_glob
else
node.add_lookup(part)
end
@@ -189,9 +193,9 @@ def add_complex_part(node, parts, param_names)
name = part[1, part.size].to_sym
param_names << name
if spans
- @matches_with && @matches_with[name] ? "((?:#{@matches_with[name]}\\/?)+)" : '(.*?)'
+ matches_with(name) ? "((?:#{matches_with(name)}\\/?)+)" : '(.*?)'
else
- "(#{(@matches_with && @matches_with[name] || '[^/]*?')})"
+ "(#{(matches_with(name) || '[^/]*?')})"
end
else
Regexp.quote(part)
View
2 lib/http_router/util.rb
@@ -12,7 +12,7 @@ def self.add_path_generation(target, route, path, path_validation_regex = nil)
code << part
dynamic = true
else
- regex << (route.matches_with && route.matches_with[part[1, part.size].to_sym] || '.*?').to_s unless path_validation_regex
+ regex << (route.matches_with(part[1, part.size].to_sym) || '.*?').to_s unless path_validation_regex
code << "\#{args.shift || (options && options.delete(:#{part[1, part.size]})) || return}"
dynamic = true
end

0 comments on commit c14f106

Please sign in to comment.