lib/merb-routing/routing_wrapper.rb
# given a hash of params, this determines the best route for us
given a hash of params, this determines the best route for us
given a hash of params this determines the best route for us
def generate(options, recall={})
    merged_options = recall.merge(options).reject { |k,v| v.nil? }
    if options[:use_route]
      best_route = Merb::Router.named_routes[options.delete(:use_route)]
    else
      best_route = nil
      best_score = 0
      routes_for_controller_and_action(merged_options[:controller], merged_options[:action]).map do |route|
        score = route.params.reject { |k,v| !((v =~ /^"(.*)"$/ && merged_options[k] == $1) || (v =~ /^\((.*)\)$/ && merged_options.has_key?(k))) }.length
        best_score, best_route = score, route if score > best_score
      end
    end
    keys_we_dont_need = best_route.params.reject { |k,v| !(v =~ /^"(.*)"$/ && merged_options[k] == $1) }.keys
    nonredundant_options = options.reject { |k,v| keys_we_dont_need.include?(k) }
    best_route.generate([nonredundant_options], recall)
  end
def generate ( options , recall = { } ) merged_options = recall . merge ( options ) . reject { | k , v | v . nil? } if options [ :use_route ] best_route = Merb :: Router . named_routes [ options . delete ( :use_route ) ] else best_route = nil best_score = 0 routes_for_controller_and_action ( merged_options [ :controller ] , merged_options [ :action ] ) . map do | route | score = route . params . reject { | k , v | ! ( ( v =~ / ^"(.*)"$ / && merged_options [ k ] == $1 ) || ( v =~ / ^ \( (.*) \) $ / && merged_options . has_key? ( k ) ) ) } . length best_score , best_route = score , route if score > best_score end end keys_we_dont_need = best_route . params . reject { | k , v | ! ( v =~ / ^"(.*)"$ / && merged_options [ k ] == $1 ) } . keys nonredundant_options = options . reject { | k , v | keys_we_dont_need . include? ( k ) } best_route . generate ( [ nonredundant_options ] , recall ) end
given a hash of params, this determines the best route for us
given a hash of params this determines the best route for us
options
<not_specific>
recall
<not_specific>