class Jellyfish::Controller
Attributes
env[R]
jellyfish[R]
routes[R]
Public Class Methods
new(routes, jellyfish)
click to toggle source
# File lib/jellyfish.rb, line 40 def initialize routes, jellyfish @routes, @jellyfish = routes, jellyfish @status, @headers, @body = nil end
Public Instance Methods
block_call(argument, block)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# File lib/jellyfish.rb, line 45 def call env @env = env block_call(*dispatch) end
cascade()
click to toggle source
# File lib/jellyfish.rb, line 62 def cascade ; halt(Jellyfish::Cascade) ; end
found(url;)
click to toggle source
# File lib/jellyfish.rb, line 64 def found url; halt(Jellyfish:: Found.new(url)); end
Also aliased as: redirect
halt(*args;)
click to toggle source
# File lib/jellyfish.rb, line 61 def halt *args; throw(:halt, *args) ; end
headers_merge(value)
click to toggle source
# File lib/jellyfish.rb, line 92 def headers_merge value if headers.nil? headers(value) else headers(headers.merge(value)) end end
log(message;)
click to toggle source
# File lib/jellyfish.rb, line 58 def log message; jellyfish.log( message, env['rack.errors']); end
log_error(error;)
click to toggle source
# File lib/jellyfish.rb, line 59 def log_error error; jellyfish.log_error(error, env['rack.errors']); end
not_found()
click to toggle source
# File lib/jellyfish.rb, line 63 def not_found ; halt(Jellyfish::NotFound.new) ; end
path_info()
click to toggle source
# File lib/jellyfish.rb, line 67 def path_info ; env['PATH_INFO'] || '/' ; end
request()
click to toggle source
# File lib/jellyfish.rb, line 60 def request ; @request ||= Rack::Request.new(env); end
request_method()
click to toggle source
# File lib/jellyfish.rb, line 68 def request_method; env['REQUEST_METHOD'] || 'GET'; end
Private Instance Methods
action_missing()
click to toggle source
# File lib/jellyfish.rb, line 117 def action_missing if jellyfish.app then cascade else not_found end end
actions()
click to toggle source
# File lib/jellyfish.rb, line 101 def actions routes[request_method.downcase] || action_missing end
dispatch()
click to toggle source
# File lib/jellyfish.rb, line 105 def dispatch actions.find{ |(route, block)| case route when String break route, block if route == path_info else#Regexp, using else allows you to use custom matcher match = route.match(path_info) break match, block if match end } || action_missing end
rack_body(v)
click to toggle source
# File lib/jellyfish.rb, line 121 def rack_body v if v.respond_to?(:each) || v.respond_to?(:to_path) then v else [v] end end