devision 0.0.3.1 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/devision/models/tokenizable.rb +46 -0
- data/lib/devision/version.rb +2 -2
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5b67a4a3a9fb587985deea0a44ba3001f02a2509
|
4
|
+
data.tar.gz: 8c7db59781cc595d064d92389276158eca7a7e20
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cb8b1c9c8793494dc4c90f800cf79ec952dcc29405b398b38f34dea83b60155cf9e516bd770d4f346cca3c3b8eb2c5dd749123779e5d89140f6e6576cd5f47d9
|
7
|
+
data.tar.gz: bb7d9ebc5a36fb77d2387d81c665d44932a63cc682c5f5e8c759396b70f7fda84ce44dbb932259967a5b546662e30ea066d2a803f024f3b3849d9cd809bea854
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Devision
|
2
|
+
module Models
|
3
|
+
module Tokenizable
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
# Fields required on the target Model
|
7
|
+
def self.required_fields(klass)
|
8
|
+
[:token]
|
9
|
+
end
|
10
|
+
|
11
|
+
included do
|
12
|
+
|
13
|
+
attr_reader :raw_token
|
14
|
+
|
15
|
+
def generate_tokens
|
16
|
+
raw, enc = Devision.token_generator.generate(self.class, :token)
|
17
|
+
@raw_token = raw
|
18
|
+
self.token = enc
|
19
|
+
end
|
20
|
+
|
21
|
+
def generate_tokens!
|
22
|
+
generate_tokens && save(validate: false)
|
23
|
+
end
|
24
|
+
|
25
|
+
def clear_token
|
26
|
+
@raw_token = nil
|
27
|
+
self.token = nil
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
module ClassMethods
|
33
|
+
|
34
|
+
def locate_record_by_token(original_raw_token)
|
35
|
+
original_token = original_raw_token
|
36
|
+
saved_token = Devision.token_generator.digest(self, :token, original_token)
|
37
|
+
|
38
|
+
tokenizable = find_or_initialize_with_error_by(:token, saved_token)
|
39
|
+
tokenizable
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
end # Tokenizable
|
45
|
+
end # Models
|
46
|
+
end # Devision
|
data/lib/devision/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: devision
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Faucett
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-09-
|
11
|
+
date: 2014-09-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -142,6 +142,7 @@ files:
|
|
142
142
|
- lib/devision/models/lockable.rb
|
143
143
|
- lib/devision/models/recoverable.rb
|
144
144
|
- lib/devision/models/rememberable.rb
|
145
|
+
- lib/devision/models/tokenizable.rb
|
145
146
|
- lib/devision/models/validatable.rb
|
146
147
|
- lib/devision/token_generator.rb
|
147
148
|
- lib/devision/version.rb
|