Class: Hobbit::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/hobbit/base.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#envObject (readonly)

Returns the value of attribute env.



49
50
51
# File 'lib/hobbit/base.rb', line 49

def env
  @env
end

#requestObject (readonly)

Returns the value of attribute request.



49
50
51
# File 'lib/hobbit/base.rb', line 49

def request
  @request
end

#responseObject (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

.routesObject



18
19
20
# File 'lib/hobbit/base.rb', line 18

def routes
  @routes ||= Hash.new { |hash, key| hash[key] = [] }
end

.settingsObject



22
23
24
# File 'lib/hobbit/base.rb', line 22

def settings
  @settings ||= { request_class: Rack::Request, response_class: Hobbit::Response }
end

.stackObject



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