Class: Vanilla::Request

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

Overview

Create a request with symbolised access to the params, and some special accessors to the snip, part and format based on our routing.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(env, app) ⇒ Request

Returns a new instance of Request.



9
10
11
12
13
14
# File 'lib/vanilla/request.rb', line 9

def initialize(env, app)
  @env = env
  @rack_request = Rack::Request.new(env)
  @app = app
  determine_request_uri_parts
end

Instance Attribute Details

#envObject (readonly)

Returns the value of attribute env.



7
8
9
# File 'lib/vanilla/request.rb', line 7

def env
  @env
end

#formatObject (readonly)

Returns the value of attribute format.



7
8
9
# File 'lib/vanilla/request.rb', line 7

def format
  @format
end

#methodObject (readonly)

Returns the value of attribute method.



7
8
9
# File 'lib/vanilla/request.rb', line 7

def method
  @method
end

#partObject (readonly)

Returns the value of attribute part.



7
8
9
# File 'lib/vanilla/request.rb', line 7

def part
  @part
end

#snip_nameObject (readonly)

Returns the value of attribute snip_name.



7
8
9
# File 'lib/vanilla/request.rb', line 7

def snip_name
  @snip_name
end

Instance Method Details

#authenticate!Object



47
48
49
# File 'lib/vanilla/request.rb', line 47

def authenticate!
  @app.authenticator.authenticate!
end

#authenticated?Boolean

Returns:

  • (Boolean)


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

def authenticated?
  @app.authenticator.authenticated?
end

#cookiesObject



27
28
29
# File 'lib/vanilla/request.rb', line 27

def cookies
  @rack_request.cookies
end

#ipObject



31
32
33
# File 'lib/vanilla/request.rb', line 31

def ip
  @rack_request.env["REMOTE_ADDR"]
end

#logoutObject



51
52
53
# File 'lib/vanilla/request.rb', line 51

def logout
  @app.authenticator.logout
end

#paramsObject



16
17
18
19
# File 'lib/vanilla/request.rb', line 16

def params
  # Don't you just love how terse functional programming tends to look like maths?
  @symbolised_params ||= @rack_request.params.inject({}) { |p, (k,v)| p[k.to_sym] = v; p }
end

#sessionObject



35
36
37
# File 'lib/vanilla/request.rb', line 35

def session
  @rack_request.env["rack.session"]
end

#snipObject

Returns the snip referenced by the request’s URL. Performs no exception handling, so if the snip does not exist, an exception will be thrown.



23
24
25
# File 'lib/vanilla/request.rb', line 23

def snip
  @app.soup[snip_name]
end

#userObject



43
44
45
# File 'lib/vanilla/request.rb', line 43

def user
  @app.authenticator.user
end