Module: Hobby::Helpers
Instance Attribute Summary collapse
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#route ⇒ Object
readonly
Returns the value of attribute route.
Instance Method Summary collapse
- #content_type(type) ⇒ Object
- #halt ⇒ Object
- #my ⇒ Object
- #not_found ⇒ Object
- #request ⇒ Object
- #response ⇒ Object
- #router ⇒ Object
- #script_name ⇒ Object
- #status(status) ⇒ Object
Instance Attribute Details
#env ⇒ Object (readonly)
Returns the value of attribute env.
5 6 7 |
# File 'lib/hobby/helpers.rb', line 5 def env @env end |
#route ⇒ Object (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 |
#halt ⇒ Object
29 30 31 |
# File 'lib/hobby/helpers.rb', line 29 def halt throw :halt, response.to_a end |
#my ⇒ Object
25 26 27 |
# File 'lib/hobby/helpers.rb', line 25 def my route.params end |
#not_found ⇒ Object
33 34 35 |
# File 'lib/hobby/helpers.rb', line 33 def not_found response.status = 404 end |
#request ⇒ Object
17 18 19 |
# File 'lib/hobby/helpers.rb', line 17 def request @request ||= self.class.request.new env end |
#response ⇒ Object
21 22 23 |
# File 'lib/hobby/helpers.rb', line 21 def response @response ||= self.class.response.new end |
#router ⇒ Object
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_name ⇒ Object
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 |