devise_last_seen 0.1.0 → 0.2.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +18 -0
- data/lib/devise_last_seen/model.rb +7 -2
- data/lib/devise_last_seen/version.rb +1 -1
- data/lib/devise_last_seen.rb +8 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cc6617bf17c0a3f8055b6bc73bb22f02b0de565927078e51d184645020475853
|
4
|
+
data.tar.gz: 7305e5febe4d734293dcd80266bd937d5382425ca01a244b497d5ffc004ca5ba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: de97558261b21595d5dde5a9edd9a0b76f79875b9ddbbffdc097b1728aa9af2ef632d935e59fed8a293046d1f6a2e5b346dc5573413b62e8607255ea497597e4
|
7
|
+
data.tar.gz: 2e142f67941c055be5992843e0279763d85845b6ec8c0674cae4fbbb5dea57d8c06d0058d0b1ace0dc0f32fcb6f0da502fcd52b857b6f2cb61ac31e4a35710b9
|
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
8
|
|
9
|
+
## [0.2.0] - 2021-08-31
|
10
|
+
### Added
|
11
|
+
- Add `Devise.last_seen_at_interval` option to allow customization of the interval
|
12
|
+
- Add `Devise.last_seen_at_attribute` option to allow customization of the attribute name
|
13
|
+
|
9
14
|
## [0.1.0] - 2021-08-31
|
10
15
|
### Added
|
11
16
|
- Basic feature that updates a pre-existent timestamp column after warden set_user.
|
data/README.md
CHANGED
@@ -31,6 +31,24 @@ class User < ApplicationRecord
|
|
31
31
|
end
|
32
32
|
```
|
33
33
|
|
34
|
+
## Configuration
|
35
|
+
|
36
|
+
Besides the column requirement you don't need customizations, but if you want to...
|
37
|
+
|
38
|
+
```rb
|
39
|
+
# config/initializers/devise.rb
|
40
|
+
|
41
|
+
Devise.setup do |config|
|
42
|
+
...
|
43
|
+
|
44
|
+
# Interval (in seconds) to update the :last_seen_at_attribute attr
|
45
|
+
# config.last_seen_at_interval = 5.minutes
|
46
|
+
|
47
|
+
# Attribute who will be updated every time a user is set by the Warden's after_save callback
|
48
|
+
# config.last_seen_at_attribute = :last_seen
|
49
|
+
end
|
50
|
+
```
|
51
|
+
|
34
52
|
## Development
|
35
53
|
|
36
54
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bundle exec rspec` to run the tests.
|
@@ -3,12 +3,17 @@ module Devise
|
|
3
3
|
module Lastseenable
|
4
4
|
def track_last_seen!
|
5
5
|
return if new_record?
|
6
|
-
return unless
|
6
|
+
return unless respond_to?(last_seen_at_attribute_writer)
|
7
|
+
return unless last_seen.to_i < (Time.now - Devise.last_seen_at_interval).to_i
|
7
8
|
|
8
|
-
|
9
|
+
public_send(last_seen_at_attribute_writer, DateTime.now)
|
9
10
|
|
10
11
|
save(validate: false)
|
11
12
|
end
|
13
|
+
|
14
|
+
def last_seen_at_attribute_writer
|
15
|
+
@last_seen_at_attribute_writer ||= :"#{Devise.last_seen_at_attribute}="
|
16
|
+
end
|
12
17
|
end
|
13
18
|
end
|
14
19
|
end
|
data/lib/devise_last_seen.rb
CHANGED
@@ -2,6 +2,14 @@ require 'devise'
|
|
2
2
|
require 'devise_last_seen/model'
|
3
3
|
require 'devise_last_seen/hook'
|
4
4
|
|
5
|
+
module Devise
|
6
|
+
# Interval (in seconds) to update the :last_seen_at_attribute attr
|
7
|
+
mattr_accessor :last_seen_at_interval, default: 5.minutes
|
8
|
+
|
9
|
+
# Attribute who will be updated every time a user is set by the Warden's after_save callback
|
10
|
+
mattr_accessor :last_seen_at_attribute, default: :last_seen
|
11
|
+
end
|
12
|
+
|
5
13
|
module DeviseLastSeen; end
|
6
14
|
|
7
15
|
Devise.add_module(:lastseenable, model: true)
|