Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Enhances ActionController with common session management functionality.
Ruby

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
gemfiles
lib
spec
.gitignore
.ruby-version
.travis.yml
CHANGELOG.md
CODE_OF_CONDUCT.md
CONTRIBUTING.md
Gemfile
Gemfile.lock
Guardfile
LICENSE.md
README.md
Rakefile
sessioner.gemspec

README.md

Overview

Gem Version Code Climate GPA Code Climate Coverage Gemnasium Status Travis CI Status Gittip

Enhances ActionController with common session management functionality beyond what is provided by default. This reduces some of the repetitive work related to storing and retrieving information from the session store.

Features

  • Auto-prefixes session keys based on controller namespace and name.
  • Auto-stores the key=value pair for pagination.
  • Auto-stores the key=value pair for search.
  • Adds convenience methods for storing key=value pairs via the session.

Requirements

  1. Any of the following Ruby VMs:
  2. Ruby on Rails 4.x.x.

Setup

For a secure install, type the following from the command line (recommended):

gem cert --add <(curl -Ls https://www.alchemists.io/gem-public.pem)
gem install sessioner --trust-policy MediumSecurity

NOTE: A HighSecurity trust policy would be best but MediumSecurity enables signed gem verification while allowing the installation of unsigned dependencies since they are beyond the scope of this gem.

For an insecure install, type the following (not recommended):

gem install sessioner

Add the following to your Gemfile:

gem "sessioner"

Usage

To use, add the sessioner macro to your controller of choice, for example:

class Admin::UsersController < Admin::BaseController
  sessioner
end

By default, this will auto-configure the session with the following keys and values:

{admin_users_page: params[:page], admin_users_search: params[:search]}

Should only page support be required but not search, then the following is possible:

class Admin::UsersController < Admin::BaseController
  sessioner search: false
end

If auto-namespaced keys aren't your thing, then you can disable as follows:

class Admin::UsersController < Admin::BaseController
  sessioner page: {namespace: false}, search: {namespace: false}
end

The session keys are customizable as well. By default, the keys default to "page" and "search". However, these could be customized as follows:

class Admin::UsersController < Admin::BaseController
  sessioner page: {key: "current_page"}, search: {key: "query"}
end

NOTE: By customizing the session keys, this also means that the parameters have to match as well. Using the example above, the session keys would be "admin_users_current_page" and "admin_users_query" while the parameter keys would need to be "current_page" and "query". The session and parameters keys must always match.

Default values can be supplied as well. For example, you might want to display new posts that are published (boolean) by default. Assuming you are using the Ransack gem in addition to this gem, the following would be possible:

class Admin::PostsController < Admin::BaseController
  sessioner search: {default: {published_true: true}}
end

In situations where default search criteria might be too complex and murky to define within via the sessioner macro, you call a method for the default options. Using the same example above, we could modify the code as follows:

class Admin::PostsController < Admin::BaseController
  sessioner search: {default: :default_search}

  private

  def default_search
    {published_true: true}
  end
end

NOTE: Any method used for default settings must be a symbol and begin with "default", otherwise the method will not be called.

Notes

Rails defaults to using a cookie store (as found via the config/initializers/session_store.rb). This limits you to 4KB of memory per session. Be wary of how much memory you plan to consume or switch to using a different session store altogether.

Tests

To test, run:

bundle exec rspec spec

Versioning

Read Semantic Versioning for details. Briefly, it means:

  • Patch (x.y.Z) - Incremented for small, backwards compatible bug fixes.
  • Minor (x.Y.z) - Incremented for new, backwards compatible public API enhancements and/or bug fixes.
  • Major (X.y.z) - Incremented for any backwards incompatible public API changes.

Code of Conduct

Please note that this project is released with a CODE OF CONDUCT. By participating in this project you agree to abide by its terms.

Contributions

Read CONTRIBUTING for details.

License

Copyright (c) 2011 Alchemists. Read the LICENSE for details.

History

Read the CHANGELOG for details. Built with Gemsmith.

Credits

Developed by Brooke Kuhlmann at Alchemists

Something went wrong with that request. Please try again.