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.
-
#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.
88 89 90 |
# File 'lib/octarine/app.rb', line 88 def request_class=(value) @request_class = value end |
Instance Method Details
#environment ⇒ Object
:call-seq: environment -> string
Returns the current enviroment. Defaults to “development”.
95 96 97 |
# File 'lib/octarine/app.rb', line 95 def environment ENV["RACK_ENV"] || "development" end |
#new(*args) ⇒ Object
:nodoc:
99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/octarine/app.rb', line 99 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.
78 79 80 81 82 83 |
# File 'lib/octarine/app.rb', line 78 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.
69 70 71 |
# File 'lib/octarine/app.rb', line 69 def restriction(name, response=401, proc=nil, &block) (@restrictions ||= {})[name] = [response, proc || block] end |