Class: Hobbit::Base
- Inherits:
-
Object
- Object
- Hobbit::Base
- Defined in:
- lib/hobbit/base.rb
Instance Attribute Summary collapse
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Class Method Summary collapse
- .map(path, &block) ⇒ Object
- .new(*args, &block) ⇒ Object
- .new! ⇒ Object
- .routes ⇒ Object
- .settings ⇒ Object
- .stack ⇒ Object
- .use(middleware, *args, &block) ⇒ Object
Instance Method Summary collapse
Instance Attribute Details
#env ⇒ Object (readonly)
Returns the value of attribute env.
49 50 51 |
# File 'lib/hobbit/base.rb', line 49 def env @env end |
#request ⇒ Object (readonly)
Returns the value of attribute request.
49 50 51 |
# File 'lib/hobbit/base.rb', line 49 def request @request end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
49 50 51 |
# File 'lib/hobbit/base.rb', line 49 def response @response end |
Class Method Details
.map(path, &block) ⇒ Object
8 9 10 |
# File 'lib/hobbit/base.rb', line 8 def map(path, &block) stack.map(path, &block) end |
.new(*args, &block) ⇒ Object
13 14 15 16 |
# File 'lib/hobbit/base.rb', line 13 def new(*args, &block) stack.run new!(*args, &block) stack end |
.new! ⇒ Object
12 |
# File 'lib/hobbit/base.rb', line 12 alias :new! :new |
.routes ⇒ Object
18 19 20 |
# File 'lib/hobbit/base.rb', line 18 def routes @routes ||= Hash.new { |hash, key| hash[key] = [] } end |
.settings ⇒ Object
22 23 24 |
# File 'lib/hobbit/base.rb', line 22 def settings @settings ||= { request_class: Rack::Request, response_class: Hobbit::Response } end |
.stack ⇒ Object
26 27 28 |
# File 'lib/hobbit/base.rb', line 26 def stack @stack ||= Rack::Builder.new end |
.use(middleware, *args, &block) ⇒ Object
30 31 32 |
# File 'lib/hobbit/base.rb', line 30 def use(middleware, *args, &block) stack.use(middleware, *args, &block) end |
Instance Method Details
#_call(env) ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/hobbit/base.rb', line 55 def _call(env) @env = env @request = self.class.settings[:request_class].new(@env) @response = self.class.settings[:response_class].new route_eval @response.finish end |
#call(env) ⇒ Object
51 52 53 |
# File 'lib/hobbit/base.rb', line 51 def call(env) dup._call(env) end |