active_session 0.0.6 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/active_session/version.rb +1 -1
- data/lib/active_session.rb +36 -0
- metadata +5 -5
data/lib/active_session.rb
CHANGED
@@ -4,7 +4,43 @@ require "active_session/attribute_methods"
|
|
4
4
|
require "active_session/errors"
|
5
5
|
|
6
6
|
module ActiveSession
|
7
|
+
# Adds a simple session mechanism for a given model.
|
8
|
+
#
|
9
|
+
# <tt>authenticates :user</tt> adds <tt>user</tt> and
|
10
|
+
# <tt>user=(new_user)</tt> methods.
|
11
|
+
#
|
12
|
+
# Options are:
|
13
|
+
# * <tt>:class_name</tt> - Specifies the class name of the
|
14
|
+
# association. Use it only if that name can't be inferred from the
|
15
|
+
# name. So <tt>authenticates :user</tt> will by default be linked
|
16
|
+
# to the User class, but if the real class name is Admin, you'll
|
17
|
+
# have to specify it using this option.
|
18
|
+
# * <tt>:foreign_key</tt> - Specifies the foreign key of the
|
19
|
+
# association. Use it only if the key can't be inferred from the
|
20
|
+
# name. So <tt>authenticates :user</tt> will by default add
|
21
|
+
# <tt>user_id</tt> and <tt>user_id=(new_user_id)</tt> methods.
|
22
|
+
# * <tt>:primary_key</tt> - Specifies the primary key of the
|
23
|
+
# association. Use it only if the key is different than <tt>id</tt>.
|
24
|
+
# * <tt>:finder_method</tt> - Specifies the finder_method for the
|
25
|
+
# association. Uses <tt>find_for_authentication</tt> method by
|
26
|
+
# default.
|
27
|
+
# * <tt>:persists</tt> - Specifies if the session model is
|
28
|
+
# persistable in the store. If set to <tt>true</tt> (default)
|
29
|
+
# <tt>foreign_key</tt> will be used to store session. So
|
30
|
+
# <tt>authenticates :user</tt> will by default store the session
|
31
|
+
# using <tt>:user_id</tt> key in the store, and use
|
32
|
+
# <tt>user_id</tt> method to fetch the stored value. You can
|
33
|
+
# change it to <tt>:email</tt> if you want to use <tt>:email</tt>
|
34
|
+
# key and <tt>email</tt> method to store the session. You can also
|
35
|
+
# turn the persistence off by passing <tt>false</tt>. Adds
|
36
|
+
# <tt>save</tt>, <tt>destroy</tt>, <tt>persisted?</tt> and a class
|
37
|
+
# method <tt>find</tt> when turned on. When turned off adds only
|
38
|
+
# <tt>persisted?</tt> method that returns false to comply with
|
39
|
+
# <tt>ActiveModel::Lint</tt>.
|
40
|
+
|
7
41
|
def authenticates(name, options = {})
|
42
|
+
options.assert_valid_keys(:class_name, :foreign_key, :primary_key, :finder_method, :persists)
|
43
|
+
|
8
44
|
klass = options.fetch(:class_name, name.to_s.classify)
|
9
45
|
foreign_key = options.fetch(:foreign_key, "#{name}_id").to_sym
|
10
46
|
primary_key = options.fetch(:primary_key, "id").to_sym
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_session
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -14,7 +14,7 @@ date: 2011-10-19 00:00:00.000000000Z
|
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activemodel
|
17
|
-
requirement: &
|
17
|
+
requirement: &11440600 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ~>
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: 3.1.1
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *11440600
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: activesupport
|
28
|
-
requirement: &
|
28
|
+
requirement: &11440080 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ~>
|
@@ -33,7 +33,7 @@ dependencies:
|
|
33
33
|
version: 3.1.1
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *11440080
|
37
37
|
description: ActiveModel session
|
38
38
|
email:
|
39
39
|
- qoobaa@gmail.com
|