Module: Octarine::App::ClassMethods
- Defined in:
- lib/octarine/app.rb
Instance Attribute Summary collapse
-
#request_class ⇒ Object
(also: #request_class)
writeonly
Set the class of the request object handed to the path handler blocks.
Instance Method Summary collapse
-
#environment ⇒ Object
:call-seq: environment -> string.
-
#method ⇒ Object
:method: default :call-seq: default {|request| block }.
-
#new(*args) ⇒ Object
:nodoc:.
-
#restrict(restriction) ⇒ Object
:call-seq: restrict(name) { block }.
-
#restriction(name, response = 401, proc = nil, &block) ⇒ Object
:call-seq: restriction(name, response=401) {|request| block } restriction(name, response=401, proc).
Instance Attribute Details
#request_class=(value) ⇒ Object (writeonly) Also known as: request_class
Set the class of the request object handed to the path handler blocks. Defaults to Octarine::Request.
87 88 89 |
# File 'lib/octarine/app.rb', line 87 def request_class=(value) @request_class = value end |
Instance Method Details
#environment ⇒ Object
:call-seq: environment -> string
Returns the current enviroment. Defaults to “development”.
94 95 96 |
# File 'lib/octarine/app.rb', line 94 def environment ENV["RACK_ENV"] || "development" end |
#method ⇒ Object
:method: default :call-seq: default {|request| block }
Adds block as a handler for when no path is matched.
46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/octarine/app.rb', line 46 [:add, :get, :post, :delete, :put, :default].each do |method| define_method(method) do |*args, &block| if Hash === args.last restrictions = Array(args.last[:restrict]) else restrictions = [] args << {} end restrictions << @current_restriction if @current_restriction args.last[:restrict] = restrictions.flatten (@handlers ||= []) << [method, *args, block] end end |
#new(*args) ⇒ Object
:nodoc:
98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/octarine/app.rb', line 98 def new(*args) # :nodoc: request_class = @request_class || Octarine::Request restrictions = @restrictions handlers = @handlers super.instance_eval do @request_class ||= request_class @router ||= HttpRouter.new @restrictions = restrictions handlers.each {|m,*args| register_handler(m, *args[0..-2], &args[-1])} self end end |
#restrict(restriction) ⇒ Object
:call-seq: restrict(name) { block }
All handlers defined within the block will be subject to the named restriction.
77 78 79 80 81 82 |
# File 'lib/octarine/app.rb', line 77 def restrict(restriction) (@current_restriction ||= []) << restriction yield ensure @current_restriction.pop end |
#restriction(name, response = 401, proc = nil, &block) ⇒ Object
:call-seq:
restriction(name, response=401) {|request| block }
restriction(name, response=401, proc)
Create a named restriction. response will be returned if the block returns true, otherwise the handler subject to the restriction will be executed as usual.
68 69 70 |
# File 'lib/octarine/app.rb', line 68 def restriction(name, response=401, proc=nil, &block) (@restrictions ||= {})[name] = [response, proc || block] end |