active_session 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/active_session/version.rb +1 -1
- data/lib/active_session.rb +33 -10
- metadata +5 -5
data/lib/active_session.rb
CHANGED
@@ -9,6 +9,7 @@ module ActiveSession
|
|
9
9
|
foreign_key = options.fetch(:foreign_key, "#{name}_id").to_sym
|
10
10
|
primary_key = options.fetch(:primary_key, "id").to_sym
|
11
11
|
finder_method = options.fetch(:finder_method, "find_for_authentication").to_sym
|
12
|
+
persists = options.fetch(:persists, foreign_key).to_sym
|
12
13
|
|
13
14
|
extend ActiveModel::Naming
|
14
15
|
include ActiveModel::AttributeMethods
|
@@ -41,18 +42,40 @@ module ActiveSession
|
|
41
42
|
remove_instance_variable("@#{name}") if instance_variable_defined?("@#{name}")
|
42
43
|
@attributes[:#{foreign_key}] = model_id
|
43
44
|
end
|
45
|
+
END
|
44
46
|
|
45
|
-
|
46
|
-
|
47
|
-
end
|
47
|
+
persists(persists)
|
48
|
+
end
|
48
49
|
|
49
|
-
|
50
|
-
persisted? && @store.delete(:#{foreign_key}) && true
|
51
|
-
end
|
50
|
+
private
|
52
51
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
52
|
+
def persists(key)
|
53
|
+
if key
|
54
|
+
instance_eval <<-END, __FILE__, __LINE__ + 1
|
55
|
+
def find(store)
|
56
|
+
new(store, :#{key} => store[:#{key}])
|
57
|
+
end
|
58
|
+
END
|
59
|
+
|
60
|
+
class_eval <<-END, __FILE__, __LINE__ + 1
|
61
|
+
def persisted?
|
62
|
+
@store[:#{key}].present? and @store[:#{key}] == #{key}
|
63
|
+
end
|
64
|
+
|
65
|
+
def destroy
|
66
|
+
persisted? && @store.delete(:#{key}) && true
|
67
|
+
end
|
68
|
+
|
69
|
+
def save
|
70
|
+
valid? && (@store[:#{key}] = #{key}) && true
|
71
|
+
end
|
72
|
+
END
|
73
|
+
else
|
74
|
+
class_eval <<-END, __FILE__, __LINE__ + 1
|
75
|
+
def persisted?
|
76
|
+
false
|
77
|
+
end
|
78
|
+
END
|
79
|
+
end
|
57
80
|
end
|
58
81
|
end
|
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.0.5
|
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: &21168040 !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: *21168040
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: activesupport
|
28
|
-
requirement: &
|
28
|
+
requirement: &21167500 !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: *21167500
|
37
37
|
description: ActiveModel session
|
38
38
|
email:
|
39
39
|
- qoobaa@gmail.com
|