Giter Site home page Giter Site logo

franc / mongo_session_store Goto Github PK

View Code? Open in Web Editor NEW

This project forked from rickyrobinson/mongo_session_store

1.0 2.0 0.0 213 KB

Rails session store class implemented for MongoMapper and Mongoid or any other MongoDB ODM

Ruby 98.99% JavaScript 1.01%

mongo_session_store's Introduction

MongoSessionStore

Description

MongoSessionStore is a collection of Rails-compatible session stores for MongoMapper and Mongoid, but also included is a generic Mongo store that works with any (or no!) Mongo ODM.

Usage

MongoSessionStore is compatible with Rails 3.0, 3.1, and 3.2.

In your Gemfile:

gem "mongo_mapper" # or "Mongoid," or another Mongo ODM, or nothing
gem "mongo_session_store-rails3"

In the session_store initializer (config/initializers/session_store.rb):

# MongoMapper
MyApp::Application.config.session_store :mongo_mapper_store

# Mongoid
MyApp::Application.config.session_store :mongoid_store

# anything else
MyApp::Application.config.session_store :mongo_store
MongoStore::Session.database = Mongo::Connection.new.db('my_app_development')

Note: If you choose to use :mongo_store you only need to set its database if you aren't using MongoMapper or Mongoid in your project.

By default, the sessions will be stored in the "sessions" collection in MongoDB. If you want to use a different collection, you can set that in the initializer:

MongoSessionStore.collection_name = "client_sessions"

And if for some reason you want to query your sessions:

# MongoMapper
MongoMapperStore::Session.where(:updated_at.gt => 2.days.ago)

# Mongoid
MongoidStore::Session.where(:updated_at.gt => 2.days.ago)

# Plain old Mongo
MongoStore::Session.where('updated_at' => { '$gt' => 2.days.ago })

Performance

The following is the benchmark run with bson_ext installed. Without bson_ext, speeds are about 10x slower. The benchmark saves 2000 sessions (~12kb each) and then finds/reloads each one.

$ ruby perf/benchmark.rb
MongoMapperStore...
3.65ms per session save
2.25ms per session load
           Total Size: 23648924
         Object count: 2000
  Average object size: 11824.462
          Index sizes: {"_id_"=>172032}
MongoidStore...
2.59ms per session save
1.33ms per session load
           Total Size: 23648924
         Object count: 2000
  Average object size: 11824.462
          Index sizes: {"_id_"=>172032}
MongoStore...
1.42ms per session save
1.11ms per session load
           Total Size: 23648924
         Object count: 2000
  Average object size: 11824.462
          Index sizes: {"_id_"=>204800}

Development

To run all the tests:

rake

To switch to the Gemfile.lock for a certain Rails version:

rake use_rails_30
rake use_rails_31
rake use_rails_32

To run the tests for a specific store:

MONGO_SESSION_STORE_ORM=mongo_mapper bundle exec rspec spec
MONGO_SESSION_STORE_ORM=mongoid bundle exec rspec spec
MONGO_SESSION_STORE_ORM=mongo bundle exec rspec spec    

Previous contributors

MongoSessionStore started as a fork of the DataMapper session store, modified to work with MongoMapper and Mongoid. Much thanks to all the previous contributors:

  • Nicolas Mérouze
  • Chris Brickley
  • Tony Pitale
  • Nicola Racco
  • Matt Powell
  • Ryan Fitzgerald

License

Copyright (c) 2011-2012 Brian Hempel Copyright (c) 2010 Nicolas Mérouze Copyright (c) 2009 Chris Brickley Copyright (c) 2009 Tony Pitale

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

mongo_session_store's People

Contributors

brianhempel avatar compressed avatar did avatar hsbt avatar mattbeedle avatar memuller avatar nmerouze avatar rickyrobinson avatar shingara avatar tpitale avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.