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.
40 41 42 43 |
# File 'lib/jellyfish.rb', line 40 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.
39 40 41 |
# File 'lib/jellyfish.rb', line 39 def env @env end |
#jellyfish ⇒ Object (readonly)
Returns the value of attribute jellyfish.
39 40 41 |
# File 'lib/jellyfish.rb', line 39 def jellyfish @jellyfish end |
#routes ⇒ Object (readonly)
Returns the value of attribute routes.
39 40 41 |
# File 'lib/jellyfish.rb', line 39 def routes @routes end |
Instance Method Details
#block_call(argument, block) ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/jellyfish.rb', line 50 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
82 83 84 85 86 87 88 89 90 |
# File 'lib/jellyfish.rb', line 82 def body value=GetValue if value == GetValue @body elsif value.nil? @body = value else @body = rack_body(value) end end |
#call(env) ⇒ Object
45 46 47 48 |
# File 'lib/jellyfish.rb', line 45 def call env @env = env block_call(*dispatch) end |
#cascade ⇒ Object
62 |
# File 'lib/jellyfish.rb', line 62 def cascade ; halt(Jellyfish::Cascade) ; end |
#found(url) ⇒ Object Also known as: redirect
64 |
# File 'lib/jellyfish.rb', line 64 def found url; halt(Jellyfish:: Found.new(url)); end |
#halt(*args) ⇒ Object
61 |
# File 'lib/jellyfish.rb', line 61 def halt *args; throw(:halt, *args) ; end |
#headers_merge(value) ⇒ Object
92 93 94 95 96 97 98 |
# File 'lib/jellyfish.rb', line 92 def headers_merge value if headers.nil? headers(value) else headers(headers.merge(value)) end end |
#log(message) ⇒ Object
58 |
# File 'lib/jellyfish.rb', line 58 def log ; jellyfish.log( , env['rack.errors']); end |
#log_error(error) ⇒ Object
59 |
# File 'lib/jellyfish.rb', line 59 def log_error error; jellyfish.log_error(error, env['rack.errors']); end |
#not_found ⇒ Object
63 |
# File 'lib/jellyfish.rb', line 63 def not_found ; halt(Jellyfish::NotFound.new) ; end |
#path_info ⇒ Object
67 |
# File 'lib/jellyfish.rb', line 67 def path_info ; env['PATH_INFO'] || '/' ; end |
#request ⇒ Object
60 |
# File 'lib/jellyfish.rb', line 60 def request ; @request ||= Rack::Request.new(env); end |
#request_method ⇒ Object
68 |
# File 'lib/jellyfish.rb', line 68 def request_method; env['REQUEST_METHOD'] || 'GET'; end |