Skip to content

Instantly share code, notes, and snippets.

@jonstorer
Forked from jjgonecrypto/fancy-pants.rb
Created January 5, 2012 20:44
Show Gist options
  • Save jonstorer/1567199 to your computer and use it in GitHub Desktop.
Save jonstorer/1567199 to your computer and use it in GitHub Desktop.
module NavigationHelpers
def path_to(page_name)
case page_name
#services
when /the list of services/
services_path
when /a new service/
new_service_path
when /edit the service named "([^"]*)"/
edit_service_path(fetch_service(name: $1))
#subscriptions
when /a new subscription for user "([^"]*)"/
new_user_subscription_path(fetch_user(username: $1))
end
end
end
World(NavigationHelpers)
module FetchHelpers
FETCH_REGEX = /^fetch_(.+)/
def method_missing(method, *args)
if method.to_s =~ FETCH_REGEX
fetch $1, *args
else
super
end
end
private
def fetch(klass, options)
klass.constantize.where(options).first or
raise "No #{klass} found for #{options.inspect}"
end
end
World(FetchHelpers)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment