has_token 0.5.0 → 0.6.0
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 +2 -2
- data/lib/has_token.rb +16 -3
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.6.0
|
data/has_token.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{has_token}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.6.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["laserlemon"]
|
12
|
-
s.date = %q{2009-
|
12
|
+
s.date = %q{2009-12-11}
|
13
13
|
s.description = %q{Generate unique tokens on your ActiveRecord models}
|
14
14
|
s.email = %q{steve@laserlemon.com}
|
15
15
|
s.extra_rdoc_files = [
|
data/lib/has_token.rb
CHANGED
@@ -25,7 +25,8 @@ module HasToken
|
|
25
25
|
:constructor => proc(&:generate_token),
|
26
26
|
:to_param => false,
|
27
27
|
:readonly => true,
|
28
|
-
:dependent => :nullify
|
28
|
+
:dependent => :nullify,
|
29
|
+
:callback => :before_create
|
29
30
|
)
|
30
31
|
|
31
32
|
class_inheritable_accessor :has_token_options
|
@@ -47,7 +48,7 @@ module HasToken
|
|
47
48
|
|
48
49
|
include InstanceMethods
|
49
50
|
|
50
|
-
|
51
|
+
send options[:callback], :create_token
|
51
52
|
end
|
52
53
|
end
|
53
54
|
|
@@ -59,6 +60,7 @@ module HasToken
|
|
59
60
|
|
60
61
|
def create_token
|
61
62
|
column = has_token_options[:column]
|
63
|
+
|
62
64
|
if value = read_attribute(column)
|
63
65
|
token = build_global_token(:value => value)
|
64
66
|
unless token.save
|
@@ -70,8 +72,19 @@ module HasToken
|
|
70
72
|
value = has_token_options[:constructor].call(self)
|
71
73
|
token = build_global_token(:value => value)
|
72
74
|
end until token.save
|
73
|
-
|
75
|
+
|
76
|
+
set_token(value)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def set_token(value)
|
81
|
+
setter = case has_token_options[:callback].to_s
|
82
|
+
when /(find|initialize|destroy)$/ then nil
|
83
|
+
when /validation/, /^before/ then :write_attribute
|
84
|
+
else :update_attribute
|
74
85
|
end
|
86
|
+
|
87
|
+
send(setter, has_token_options[:column], value) if setter
|
75
88
|
end
|
76
89
|
end
|
77
90
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: has_token
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- laserlemon
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-12-11 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|