Class: CookiePlugin

Inherits:
Rubko::Plugin show all
Defined in:
lib/rubko/plugins/cookie.rb

Instance Attribute Summary collapse

Attributes included from Rubko::Base

#parent

Instance Method Summary collapse

Methods inherited from Rubko::Plugin

#config

Methods included from Rubko::Base

#camelize, #finalize, #httpGet, #initialize, #jsonParse, #loadController, #loadFile, #loadModel, #loadPlugin, #loadView, #method_missing, #uncamelize

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Rubko::Base

Instance Attribute Details

#domainObject

Returns the value of attribute domain.



13
14
15
# File 'lib/rubko/plugins/cookie.rb', line 13

def domain
  @domain
end

#expiresObject

Returns the value of attribute expires.



13
14
15
# File 'lib/rubko/plugins/cookie.rb', line 13

def expires
  @expires
end

#httpOnlyObject

Returns the value of attribute httpOnly.



13
14
15
# File 'lib/rubko/plugins/cookie.rb', line 13

def httpOnly
  @httpOnly
end

#maxAgeObject

Returns the value of attribute maxAge.



13
14
15
# File 'lib/rubko/plugins/cookie.rb', line 13

def maxAge
  @maxAge
end

#pathObject

Returns the value of attribute path.



13
14
15
# File 'lib/rubko/plugins/cookie.rb', line 13

def path
  @path
end

#secureObject

Returns the value of attribute secure.



13
14
15
# File 'lib/rubko/plugins/cookie.rb', line 13

def secure
  @secure
end

Instance Method Details

#[](key = nil) ⇒ Object



32
33
34
# File 'lib/rubko/plugins/cookie.rb', line 32

def [](key = nil)
	key.nil? ? cookies : cookies[key]
end

#[]=(key, val) ⇒ Object



36
37
38
39
40
41
42
43
44
# File 'lib/rubko/plugins/cookie.rb', line 36

def []=(key, val)
	if val.nil?
		Rack::Utils.delete_cookie_header! headers, key, domain: domain, path: path
	else
		Rack::Utils.set_cookie_header! headers, key, value: val, domain: domain, path: path,
		httponly: httpOnly, secure: secure, max_age: maxAge.to_s, expires: expires
	end
	val
end

#initObject



2
3
4
5
6
7
8
9
10
11
# File 'lib/rubko/plugins/cookie.rb', line 2

def init
	@domain = nil
	@path = url.base
	@httpOnly = true
	@secure = false

	@maxAge = 30*24*60*60
	@expires = nil
	config
end

#ipObject



28
29
30
# File 'lib/rubko/plugins/cookie.rb', line 28

def ip
	Rack::Request.new(env).ip.encode 'UTF-8'
end