Skip to content

Instantly share code, notes, and snippets.

@braidn
Last active December 15, 2015 08:39
Show Gist options
  • Save braidn/5232767 to your computer and use it in GitHub Desktop.
Save braidn/5232767 to your computer and use it in GitHub Desktop.
just playing with a little / new framework
class MyApp < Scorched::Controller
render_defaults.merge!(
engine: :haml,
layout: :index
)
#redirect after a 404 error
after status:404 do
redirect('/')
end
middleware << proc {
use Rack::Session::Cookie, secret: 'gotakeadump'
}
#simple route, nothing special
#This block accepts all HTTP methods if (none defined)
route '/' do
@response = 'Welcome Home'
#default engine seems to be 'erb' which... is an opinion!
#which means there is some explaining to do http://scorchedrb.com
render(:index)
end
#little more complex, captures all methods and places item into the return value
#the 5 is a priority value
#If we wanted to specify one method on this request we could omit route and put method.downcase
route '/*', 5, methods: ['POST', 'GET', 'DELETE'] do |capture|
error = "I see someone is looking for #{capture}, feel free to fuck off"
#flash session accessed during next request
#IF NOT ACCESSED it hangs around until it is accessed
flash[:error] = error
render(:index)
end
#this works the same as above just captures both the item and the slash (/)
get '/**' do |capture|
@response = "I see you are looking for something with a #{capture}"
end
#regex that needs to meet the has_name condition defined above
get "/%r{$a}", has_name: true do |capture|
@response = "Caught a regex! #{capture}"
#this flash is nested and fires much the same as the flash[:error] above
if capture == 'assboom'
flash(:dick)[:nice_try] = 'Wow, clever'
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment