Skip to content

Instantly share code, notes, and snippets.

@carllerche
Created April 16, 2009 07:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save carllerche/96282 to your computer and use it in GitHub Desktop.
Save carllerche/96282 to your computer and use it in GitHub Desktop.
def generate(params, defaults = {})
unless (v_controller = (params[:controller] || defaults[:controller]).to_s) =~ /^(?-mix:[^\/.,;?]+)$/
raise ArgumentError, "Condition cannot be generated with #{params.inspect}"
end
"/#{params.delete(:controller) ; v_controller}#{if (params[:action] || params[:id]) && (v_action = (params[:action] || defaults[:action]).to_s) =~ /^(?-mix:[^\/.,;?]+)$/ ; "/#{params.delete(:action) ; v_action}#{if (params[:id]) && (v_id = (params[:id] || defaults[:id]).to_s) =~ /^(?-mix:[^\/.,;?]+)$/ ; "/#{params.delete(:id) ; v_id}" ; end}" ; end}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment