class Florida::SinatraServer::Router
Public Class Methods
new(app, sinatra)
click to toggle source
# File lib/florida/sinatra_server/router.rb, line 2 def initialize(app, sinatra) @app = app @sinatra = sinatra end
setup(app, sinatra)
click to toggle source
# File lib/florida/sinatra_server/router.rb, line 7 def self.setup(app, sinatra) self.new(app, sinatra).routing! end
Private Class Methods
index_routing_matcher(path)
click to toggle source
# File lib/florida/sinatra_server/router.rb, line 35 def self.index_routing_matcher(path) %r{\A#{path}(\.[\w]+)?/?\z} end
show_routing_matcher(path)
click to toggle source
# File lib/florida/sinatra_server/router.rb, line 39 def self.show_routing_matcher(path) %r{\A#{path}/(\w+)(\.[\w]+)?/?\z} end
Public Instance Methods
routing!()
click to toggle source
# File lib/florida/sinatra_server/router.rb, line 11 def routing! @app.routings.each do |path, data| setup_routing(path, data) end end
Private Instance Methods
setup_routing(path, params)
click to toggle source
# File lib/florida/sinatra_server/router.rb, line 18 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