Class: Jellyfish::Controller

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

Overview


Direct Known Subclasses

Sinatra

Constant Summary

Constants included from Jellyfish

LOCATION, PATH_INFO, RACK_ERRORS, REQUEST_METHOD, VERSION

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Jellyfish

#controller, #protect

Constructor Details

#initialize(routes) ⇒ Controller

Returns a new instance of Controller.



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

def initialize routes
  @routes = routes
end

Instance Attribute Details

#envObject (readonly)

Returns the value of attribute env.



37
38
39
# File 'lib/jellyfish.rb', line 37

def env
  @env
end

#routesObject (readonly)

Returns the value of attribute routes.



37
38
39
# File 'lib/jellyfish.rb', line 37

def routes
  @routes
end

Instance Method Details

#block_call(argument, block) ⇒ Object



47
48
49
50
51
# File 'lib/jellyfish.rb', line 47

def block_call argument, block
  ret = instance_exec(argument, &block)
  body ret if body.nil? # prefer explicitly set values
  [status || 200, headers || {}, body]
end

#body(value = nil) ⇒ Object



72
73
74
75
76
77
78
79
80
# File 'lib/jellyfish.rb', line 72

def body value=nil
  if value.nil?
    @body
  elsif value.respond_to?(:each) # per rack SPEC
    @body = value
  else
    @body = [value]
  end
end

#call(env) ⇒ Object



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

def call env
  @env = env
  block_call(*dispatch)
end

#forwardObject

Raises:



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

def forward  ; raise(NotFound.new)  ; end

#found(url) ⇒ Object Also known as: redirect

Raises:



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

def found url; raise(Found.new(url)); end

#headers_merge(value) ⇒ Object



82
83
84
85
86
87
88
# File 'lib/jellyfish.rb', line 82

def headers_merge value
  if headers.nil?
    headers(value)
  else
    headers(headers.merge(value))
  end
end

#path_infoObject



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

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

#request_methodObject



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

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