Class: Jellyfish::Controller
- Inherits:
-
Object
- Object
- Jellyfish::Controller
- Defined in:
- lib/jellyfish.rb
Overview
Instance Attribute Summary collapse
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#jellyfish ⇒ Object
readonly
Returns the value of attribute jellyfish.
-
#routes ⇒ Object
readonly
Returns the value of attribute routes.
Instance Method Summary collapse
- #block_call(argument, block) ⇒ Object
- #body(value = GetValue) ⇒ Object
- #call(env) ⇒ Object
- #cascade ⇒ Object
- #found(url) ⇒ Object (also: #redirect)
- #halt(*args) ⇒ Object
- #headers_merge(value) ⇒ Object
-
#initialize(routes, jellyfish) ⇒ Controller
constructor
A new instance of Controller.
- #log(message) ⇒ Object
- #log_error(error) ⇒ Object
- #not_found ⇒ Object
- #path_info ⇒ Object
- #request ⇒ Object
- #request_method ⇒ Object
Constructor Details
#initialize(routes, jellyfish) ⇒ Controller
Returns a new instance of Controller.
42 43 44 45 |
# File 'lib/jellyfish.rb', line 42 def initialize routes, jellyfish @routes, @jellyfish = routes, jellyfish @status, @headers, @body = nil end |
Instance Attribute Details
#env ⇒ Object (readonly)
Returns the value of attribute env.
41 42 43 |
# File 'lib/jellyfish.rb', line 41 def env @env end |
#jellyfish ⇒ Object (readonly)
Returns the value of attribute jellyfish.
41 42 43 |
# File 'lib/jellyfish.rb', line 41 def jellyfish @jellyfish end |
#routes ⇒ Object (readonly)
Returns the value of attribute routes.
41 42 43 |
# File 'lib/jellyfish.rb', line 41 def routes @routes end |
Instance Method Details
#block_call(argument, block) ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/jellyfish.rb', line 52 def block_call argument, block val = instance_exec(argument, &block) [status || 200, headers || {}, body || rack_body(val || '')] rescue LocalJumpError log("Use `next' if you're trying to `return' or `break' from a block.") raise end |
#body(value = GetValue) ⇒ Object
84 85 86 87 88 89 90 91 92 |
# File 'lib/jellyfish.rb', line 84 def body value=GetValue if value == GetValue @body elsif value.nil? @body = value else @body = rack_body(value) end end |
#call(env) ⇒ Object
47 48 49 50 |
# File 'lib/jellyfish.rb', line 47 def call env @env = env block_call(*dispatch) end |
#cascade ⇒ Object
64 |
# File 'lib/jellyfish.rb', line 64 def cascade ; halt(Jellyfish::Cascade) ; end |
#found(url) ⇒ Object Also known as: redirect
66 |
# File 'lib/jellyfish.rb', line 66 def found url; halt(Jellyfish:: Found.new(url)); end |
#halt(*args) ⇒ Object
63 |
# File 'lib/jellyfish.rb', line 63 def halt *args; throw(:halt, *args) ; end |
#headers_merge(value) ⇒ Object
94 95 96 97 98 99 100 |
# File 'lib/jellyfish.rb', line 94 def headers_merge value if headers.nil? headers(value) else headers(headers.merge(value)) end end |
#log(message) ⇒ Object
60 |
# File 'lib/jellyfish.rb', line 60 def log ; jellyfish.log( , env['rack.errors']); end |
#log_error(error) ⇒ Object
61 |
# File 'lib/jellyfish.rb', line 61 def log_error error; jellyfish.log_error(error, env['rack.errors']); end |
#not_found ⇒ Object
65 |
# File 'lib/jellyfish.rb', line 65 def not_found ; halt(Jellyfish::NotFound.new) ; end |
#path_info ⇒ Object
69 |
# File 'lib/jellyfish.rb', line 69 def path_info ; env['PATH_INFO'] || '/' ; end |
#request ⇒ Object
62 |
# File 'lib/jellyfish.rb', line 62 def request ; @request ||= Rack::Request.new(env); end |
#request_method ⇒ Object
70 |
# File 'lib/jellyfish.rb', line 70 def request_method; env['REQUEST_METHOD'] || 'GET'; end |