Sha256: 6ccea722e0b36a4051342b444f4064b71c772c61234a3b2b294d504f85a7d68a
Contents?: true
Size: 920 Bytes
Versions: 1
Compression:
Stored size: 920 Bytes
Contents
class Florida::SinatraServer::Router def initialize(app, sinatra) @app = app @sinatra = sinatra end def self.setup(app, sinatra) self.new(app, sinatra).routing! end def routing! @app.routings.each do |path, data| setup_routing(path, data) end end private def setup_routing(path, params) controller_class = params[:to] controller = controller_class.new if controller.respond_to? :index @sinatra.get self.class.index_routing_matcher(path) do controller_class.new(self).index end end if controller.respond_to? :show @sinatra.get(self.class.show_routing_matcher(path)) do controller_class.new(self).show(self.params[:captures].first) end end end def self.index_routing_matcher(path) %r{\A#{path}(\.[\w]+)?/?\z} end def self.show_routing_matcher(path) %r{\A#{path}/(\w+)(\.[\w]+)?/?\z} end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
florida-0.0.2 | lib/florida/sinatra_server/router.rb |