Class: SessionPlugin
- Inherits:
-
Rubko::Plugin
- Object
- Rubko::Plugin
- SessionPlugin
- Defined in:
- lib/rubko/plugins/session.rb
Instance Attribute Summary collapse
-
#cookie ⇒ Object
Returns the value of attribute cookie.
-
#hashSize ⇒ Object
Returns the value of attribute hashSize.
-
#name ⇒ Object
Returns the value of attribute name.
-
#path ⇒ Object
Returns the value of attribute path.
-
#purgeRate ⇒ Object
Returns the value of attribute purgeRate.
-
#storage ⇒ Object
Returns the value of attribute storage.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
Attributes included from Rubko::Base
Class Method Summary collapse
Instance Method Summary collapse
- #[]=(*args, val) ⇒ Object
- #create ⇒ Object
- #destroy ⇒ Object
- #id ⇒ Object
- #init ⇒ Object
- #ip? ⇒ Boolean
- #purge ⇒ Object
- #resid ⇒ Object
Methods inherited from Rubko::Plugin
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
#cookie ⇒ Object
Returns the value of attribute cookie.
35 36 37 |
# File 'lib/rubko/plugins/session.rb', line 35 def @cookie end |
#hashSize ⇒ Object
Returns the value of attribute hashSize.
35 36 37 |
# File 'lib/rubko/plugins/session.rb', line 35 def hashSize @hashSize end |
#name ⇒ Object
Returns the value of attribute name.
35 36 37 |
# File 'lib/rubko/plugins/session.rb', line 35 def name @name end |
#path ⇒ Object
Returns the value of attribute path.
35 36 37 |
# File 'lib/rubko/plugins/session.rb', line 35 def path @path end |
#purgeRate ⇒ Object
Returns the value of attribute purgeRate.
35 36 37 |
# File 'lib/rubko/plugins/session.rb', line 35 def purgeRate @purgeRate end |
#storage ⇒ Object
Returns the value of attribute storage.
35 36 37 |
# File 'lib/rubko/plugins/session.rb', line 35 def storage @storage end |
#timeout ⇒ Object
Returns the value of attribute timeout.
35 36 37 |
# File 'lib/rubko/plugins/session.rb', line 35 def timeout @timeout end |
Class Method Details
.delegate(*funcs) ⇒ Object
77 78 79 80 81 82 83 84 |
# File 'lib/rubko/plugins/session.rb', line 77 def self.delegate(*funcs) funcs.each { |func| define_method(func) { |*args| sid = id storage.send func, name, sid, *args } } end |
Instance Method Details
#[]=(*args, val) ⇒ Object
71 72 73 74 75 |
# File 'lib/rubko/plugins/session.rb', line 71 def []=(*args, val) create return unless id storage[name, id, *args] = val end |
#create ⇒ Object
47 48 49 50 51 |
# File 'lib/rubko/plugins/session.rb', line 47 def create return if id [name] = @id = hash unless ip? storage[name, @id] = Time.new end |
#destroy ⇒ Object
53 54 55 56 57 58 |
# File 'lib/rubko/plugins/session.rb', line 53 def destroy return unless id storage.prune name, id [name] = nil @id = false end |
#id ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/rubko/plugins/session.rb', line 14 def id if @id.nil? config purge if 0 == rand(purgeRate) @id = if ip? .ip else [name] || false end if @id if time = storage[name, @id] destroy if Time.now - time > timeout end storage[name, @id] = Time.new end end @id end |
#init ⇒ Object
4 5 6 7 8 9 10 11 12 |
# File 'lib/rubko/plugins/session.rb', line 4 def init @name = :session # cookie name @timeout = 2*60*60 # session timeout in seconds of inactivity @purgeRate = 10_000 # interval (requests) to clear expired sessions @hashSize = 16 # entropy of hash in byes @storage = memory @cookie = loadPlugin :cookie end |
#ip? ⇒ Boolean
37 38 39 |
# File 'lib/rubko/plugins/session.rb', line 37 def ip? name == :ip end |
#purge ⇒ Object
41 42 43 44 45 |
# File 'lib/rubko/plugins/session.rb', line 41 def purge storage.values(name).each { |id, time| destroy if Time.now - time > timeout } end |
#resid ⇒ Object
64 65 66 67 |
# File 'lib/rubko/plugins/session.rb', line 64 def resid return if ip? || !id storage.rename name, id, ([name] = hash) end |