Module: Hobby::Helpers

Extended by:
Forwardable
Included in:
Hobby
Defined in:
lib/hobby/helpers.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#envObject (readonly)

Returns the value of attribute env.



5
6
7
# File 'lib/hobby/helpers.rb', line 5

def env
  @env
end

#routeObject (readonly)

Returns the value of attribute route.



5
6
7
# File 'lib/hobby/helpers.rb', line 5

def route
  @route
end

Instance Method Details

#content_type(type) ⇒ Object



37
38
39
40
# File 'lib/hobby/helpers.rb', line 37

def content_type type
  mime_type = Rack::Mime::MIME_TYPES.fetch ".#{type}"
  response.add_header 'Content-Type', mime_type
end

#haltObject



29
30
31
# File 'lib/hobby/helpers.rb', line 29

def halt
  throw :halt, response.to_a
end

#myObject



25
26
27
# File 'lib/hobby/helpers.rb', line 25

def my
  route.params
end

#not_foundObject



33
34
35
# File 'lib/hobby/helpers.rb', line 33

def not_found
  response.status = 404
end

#requestObject



17
18
19
# File 'lib/hobby/helpers.rb', line 17

def request
  @request ||= self.class.request.new env
end

#responseObject



21
22
23
# File 'lib/hobby/helpers.rb', line 21

def response
  @response ||= self.class.response.new
end

#routerObject



7
8
9
10
11
12
13
# File 'lib/hobby/helpers.rb', line 7

def router
  @router ||= begin
                router = self.class.router.clone
                router.app = self
                router
              end
end

#script_nameObject



46
47
48
# File 'lib/hobby/helpers.rb', line 46

def script_name
  env.fetch 'SCRIPT_NAME'
end

#status(status) ⇒ Object



42
43
44
# File 'lib/hobby/helpers.rb', line 42

def status status
  response.status = status
end