diff options
author | Azul <azul@riseup.net> | 2016-05-12 14:30:23 +0200 |
---|---|---|
committer | Azul <azul@riseup.net> | 2016-05-12 14:30:23 +0200 |
commit | aeb0f39362b2195d4aec418349538b5f8443f693 (patch) | |
tree | 66f599cac18e14e8fdc278ac080a48e35ffd68d2 /vendor/gems/couchrest_session_store/lib/couchrest/session | |
parent | 90e2145e33913ff59b99b81a660cb730e3c7efd8 (diff) |
minor: no need to vendor couchrest_session_store
Diffstat (limited to 'vendor/gems/couchrest_session_store/lib/couchrest/session')
3 files changed, 0 insertions, 140 deletions
diff --git a/vendor/gems/couchrest_session_store/lib/couchrest/session/document.rb b/vendor/gems/couchrest_session_store/lib/couchrest/session/document.rb deleted file mode 100644 index dc938cf..0000000 --- a/vendor/gems/couchrest_session_store/lib/couchrest/session/document.rb +++ /dev/null @@ -1,34 +0,0 @@ -require 'time' - -class CouchRest::Session::Document < CouchRest::Document - include CouchRest::Model::Configuration - include CouchRest::Model::Connection - include CouchRest::Model::Rotation - - rotate_database 'sessions', - :every => 1.month, :expiration_field => :expires - - def self.fetch(id) - database.get(id) - end - - def self.find_by_expires(options = {}) - options[:reduce] ||= false - design = database.get '_design/Session' - response = design.view :by_expires, options - response['rows'] - end - - def self.create_database!(name=nil) - db = super(name) - begin - db.get('_design/Session') - rescue CouchRest::NotFound - design = File.read(File.expand_path('../../../../design/Session.json', __FILE__)) - design = JSON.parse(design) - db.save_doc(design.merge({"_id" => "_design/Session"})) - end - db - end - -end diff --git a/vendor/gems/couchrest_session_store/lib/couchrest/session/store.rb b/vendor/gems/couchrest_session_store/lib/couchrest/session/store.rb deleted file mode 100644 index 516d5dd..0000000 --- a/vendor/gems/couchrest_session_store/lib/couchrest/session/store.rb +++ /dev/null @@ -1,94 +0,0 @@ -class CouchRest::Session::Store < ActionDispatch::Session::AbstractStore - - # delegate configure to document - def self.configure(*args, &block) - CouchRest::Session::Document.configure *args, &block - end - - def self.set_options(options) - @options = options - if @options[:database] - CouchRest::Session::Document.use_database @options[:database] - end - end - - def initialize(app, options = {}) - super - self.class.set_options(options) - end - - def cleanup(rows) - rows.each do |row| - doc = CouchRest::Session::Document.fetch(row['id']) - doc.delete - end - end - - def expired - CouchRest::Session::Document.find_by_expires startkey: 1, - endkey: Time.now.utc.iso8601 - end - - def never_expiring - CouchRest::Session::Document.find_by_expires endkey: 1 - end - - private - - def get_session(env, sid) - if session = fetch_session(sid) - [sid, session] - else - [generate_sid, {}] - end - rescue CouchRest::NotFound - # session data does not exist anymore - return [sid, {}] - rescue CouchRest::Unauthorized, - Errno::EHOSTUNREACH, - Errno::ECONNREFUSED => e - # can't connect to couch. We add some status to the session - # so the app can react. (Display error for example) - return [sid, {"_status" => {"couch" => "unreachable"}}] - end - - def set_session(env, sid, session, options) - raise CouchRest::NotFound if /^_design\/(.*)/ =~ sid - couchrest_session = build_or_update_doc(sid, session, options) - couchrest_session.save - return sid - # if we can't store the session we just return false. - rescue CouchRest::Unauthorized, - Errno::EHOSTUNREACH, - Errno::ECONNREFUSED => e - return false - end - - def destroy_session(env, sid, options) - doc = secure_get(sid) - doc.delete - generate_sid unless options[:drop] - rescue CouchRest::NotFound - # already destroyed - we're done. - generate_sid unless options[:drop] - end - - def fetch_session(sid) - return nil unless sid - couchrest_session = secure_get(sid) - couchrest_session.to_session unless couchrest_session.expired? - end - - def build_or_update_doc(sid, session, options) - CouchRest::Session.build_or_update(sid, session, options) - end - - # prevent access to design docs - # this should be prevented on a couch permission level as well. - # but better be save than sorry. - def secure_get(sid) - raise CouchRest::NotFound if /^_design\/(.*)/ =~ sid - CouchRest::Session.fetch(sid) - end - -end diff --git a/vendor/gems/couchrest_session_store/lib/couchrest/session/utility.rb b/vendor/gems/couchrest_session_store/lib/couchrest/session/utility.rb deleted file mode 100644 index 3982c28..0000000 --- a/vendor/gems/couchrest_session_store/lib/couchrest/session/utility.rb +++ /dev/null @@ -1,12 +0,0 @@ -module CouchRest::Session::Utility - module_function - - def marshal(data) - ::Base64.encode64(Marshal.dump(data)) if data - end - - def unmarshal(data) - Marshal.load(::Base64.decode64(data)) if data - end - -end |