has_token 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/has_token.gemspec +1 -1
- data/lib/has_token.rb +5 -7
- metadata +1 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.1
|
data/has_token.gemspec
CHANGED
data/lib/has_token.rb
CHANGED
@@ -15,7 +15,8 @@ module HasToken
|
|
15
15
|
:characters => [('a'..'z'), ('A'..'Z'), ('0'..'9')].map(&:to_a).sum,
|
16
16
|
:constructor => proc(&:generate_token),
|
17
17
|
:to_param => false,
|
18
|
-
:readonly => true
|
18
|
+
:readonly => true,
|
19
|
+
:dependent => :nullify
|
19
20
|
)
|
20
21
|
|
21
22
|
class_inheritable_accessor :has_token_options
|
@@ -23,10 +24,9 @@ module HasToken
|
|
23
24
|
self.has_token_options = options
|
24
25
|
|
25
26
|
if options[:to_param]
|
26
|
-
|
27
|
+
define_method(:to_param_with_token) do
|
27
28
|
read_attribute(options[:column])
|
28
29
|
end
|
29
|
-
|
30
30
|
alias_method_chain :to_param, :token
|
31
31
|
end
|
32
32
|
|
@@ -34,7 +34,7 @@ module HasToken
|
|
34
34
|
attr_readonly(options[:column])
|
35
35
|
end
|
36
36
|
|
37
|
-
has_one :global_token, :class_name => 'Token', :as => :parent, :dependent => :
|
37
|
+
has_one :global_token, :class_name => 'Token', :as => :parent, :dependent => options[:dependent]
|
38
38
|
|
39
39
|
include InstanceMethods
|
40
40
|
|
@@ -50,9 +50,7 @@ module HasToken
|
|
50
50
|
|
51
51
|
def create_token
|
52
52
|
column = has_token_options[:column]
|
53
|
-
value = read_attribute(column)
|
54
|
-
|
55
|
-
if value
|
53
|
+
if value = read_attribute(column)
|
56
54
|
token = build_global_token(:value => value)
|
57
55
|
unless token.save
|
58
56
|
errors.add(column, token.errors.on(:value))
|