Sha256: 9d3f003afd5d551db49786d103d8ef1371da3b9734ce57a59e95645248d9ec63
Contents?: true
Size: 1.25 KB
Versions: 1
Compression:
Stored size: 1.25 KB
Contents
class RoutingError < Exception; end class InvalidRoute < RoutingError; end class InvalidGetRoute < InvalidRoute; end module Nephos module Route def self.add(what, verb) Nephos::Route::ALL << what.merge(verb: verb) puts "[#{verb}] #{what[:url]} \t ---> \t #{what[:controller]}##{what[:method]}" end def self.check!(what) raise InvalidGetRoute if not what.keys.include? :url raise InvalidGetRoute if not what.keys.include? :controller raise InvalidGetRoute if not what.keys.include? :method # TODO: more check to do end end end def route_prefix @route_prefix ||= [] File.join(["/"] + @route_prefix) end # @params what [Hash] def get what what[:url] = File.expand_path File.join(route_prefix, what[:url]) Nephos::Route.check!(what) Nephos::Route.add(what, "GET") end # @params what [Hash] def post what what[:url] = File.join(route_prefix, what[:url]) Nephos::Route.check!(what) Nephos::Route.add(what, "POST") end # @params what [Hash] def put what what[:url] = File.join(route_prefix, what[:url]) Nephos::Route.check!(what) Nephos::Route.add(what, "PUT") end def resource(name, &block) @route_prefix ||= [] @route_prefix << name block.call @route_prefix.pop end load 'routes.rb' puts
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
nephos-server-0.1.6 | lib/nephos-server/routing/load.rb |