trabajo-afectivo/lib/session_helper.rb

53 lines
1.4 KiB
Ruby
Raw Normal View History

module SessionHelper
2012-10-23 20:25:42 +00:00
def self.default_collections(user)
# auto population collections, store all here
default_collection = {}
assets = {}
# load collections to deliver from external files
dir = File.expand_path('../../', __FILE__)
files = Dir.glob( "#{dir}/app/controllers/sessions/collection_*.rb" )
files.each { |file|
load file
(default_collection, assets ) = ExtraCollection.session( default_collection, assets, user )
}
[default_collection, assets]
end
2013-12-08 16:01:54 +00:00
2014-09-09 23:42:20 +00:00
def self.models(user = nil)
models = {}
objects = ObjectManager.list_objects
2014-09-09 23:42:20 +00:00
objects.each {|object|
attributes = ObjectManager::Attribute.by_object(object, user)
models[object] = attributes
}
models
end
2013-12-08 16:01:54 +00:00
def self.cleanup_expired
2015-06-23 12:17:04 +00:00
# delete temp. sessions
ActiveRecord::SessionStore::Session.where('persistent IS NULL AND updated_at < ?', Time.zone.now - 2.hours ).delete_all
2015-06-23 12:17:04 +00:00
# web sessions older the x days
ActiveRecord::SessionStore::Session.where('updated_at < ?', Time.zone.now - 90.days ).delete_all
2013-12-08 16:01:54 +00:00
end
def self.get(id)
ActiveRecord::SessionStore::Session.find_by( id: id )
2013-12-08 16:01:54 +00:00
end
def self.list(limit = 10_000)
2013-12-08 16:01:54 +00:00
ActiveRecord::SessionStore::Session.order('updated_at DESC').limit(limit)
end
def self.destroy(id)
session = ActiveRecord::SessionStore::Session.find_by( id: id )
2013-12-08 16:01:54 +00:00
return if !session
session.destroy
end
end