Class: Jellyfish::Controller

Inherits:
Object
  • Object
show all
Defined in:
lib/jellyfish.rb

Overview


Instance Attribute Summary collapse

Instance Method Summary collapse

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

#envObject (readonly)

Returns the value of attribute env.



41
42
43
# File 'lib/jellyfish.rb', line 41

def env
  @env
end

#jellyfishObject (readonly)

Returns the value of attribute jellyfish.



41
42
43
# File 'lib/jellyfish.rb', line 41

def jellyfish
  @jellyfish
end

#routesObject (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

#cascadeObject



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     message; jellyfish.log(    message, 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_foundObject



65
# File 'lib/jellyfish.rb', line 65

def not_found ;  halt(Jellyfish::NotFound.new)     ; end

#path_infoObject



69
# File 'lib/jellyfish.rb', line 69

def path_info     ; env['PATH_INFO']      || '/'  ; end

#requestObject



62
# File 'lib/jellyfish.rb', line 62

def request   ; @request ||= Rack::Request.new(env); end

#request_methodObject



70
# File 'lib/jellyfish.rb', line 70

def request_method; env['REQUEST_METHOD'] || 'GET'; end