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.



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

#envObject (readonly)

Returns the value of attribute env.



39
40
41
# File 'lib/jellyfish.rb', line 39

def env
  @env
end

#jellyfishObject (readonly)

Returns the value of attribute jellyfish.



39
40
41
# File 'lib/jellyfish.rb', line 39

def jellyfish
  @jellyfish
end

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

#cascadeObject



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



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

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

#path_infoObject



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

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

#requestObject



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

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

#request_methodObject



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

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