Sha256: b69465b03211f0d7e9ca8ee5c66fdf09a8c9f95e5a259b2102d8e39fb55bd88e
Contents?: true
Size: 1.18 KB
Versions: 3
Compression:
Stored size: 1.18 KB
Contents
# Base class that represents your Rack app module Newark module App def self.included(klass) klass.instance_variable_set :@routes, [] klass.instance_variable_set :@before_hooks, [] klass.instance_variable_set :@after_hooks, [] klass.extend ClassMethods end HTTP_VERBS = [ :delete, :get, :head, :options, :patch, :post, :put, :trace ].freeze module ClassMethods HTTP_VERBS.each do |verb| define_method verb do |path, options = {}, &block| options.merge!(request_method: verb.to_s.upcase) define_route(path, options, &block) end end def define_route(path, options, &block) @routes << Route.new(path, options, block) end def before(&block) @before_hooks << block end def after(&block) @after_hooks << block end end def call(env) Router.new(self, env).route! end def routes self.class.instance_variable_get :@routes end def before_hooks self.class.instance_variable_get :@before_hooks end def after_hooks self.class.instance_variable_get :@after_hooks end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
newark-0.0.4 | lib/newark/app.rb |
newark-0.0.3 | lib/newark/app.rb |
newark-0.0.1 | lib/newark/app.rb |