Skip to content

Instantly share code, notes, and snippets.

@carllerche
Created April 16, 2009 07:03
Show Gist options
  • Select an option

  • Save carllerche/96282 to your computer and use it in GitHub Desktop.

Select an option

Save carllerche/96282 to your computer and use it in GitHub Desktop.

Revisions

  1. carllerche created this gist Apr 16, 2009.
    6 changes: 6 additions & 0 deletions gistfile1.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    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