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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7bdaab8a95568ce6a0cf28fb9314f5ce1f9a4254442c7955cb6dd474202a35f2
4
- data.tar.gz: 7bce08d3831c59f262f8dcf30bde72d840159703b7a2c7147c320019a72db191
3
+ metadata.gz: cc6617bf17c0a3f8055b6bc73bb22f02b0de565927078e51d184645020475853
4
+ data.tar.gz: 7305e5febe4d734293dcd80266bd937d5382425ca01a244b497d5ffc004ca5ba
5
5
  SHA512:
6
- metadata.gz: b1e3c1e086e89f15652ad1f8cda8cc0e099f62f07d74bc2ce53258389514bd0280ab59193d911e7650784819e3313130700325708c65f6a8f58b0734961a6bd4
7
- data.tar.gz: 241905e3cc2e21b5cfebd3fbb61979225a6150a3ddc5cab8ba3507dd924616b429b481b3bd52ff9d4aa8246fa1a6cec34c688146b29b0c0e633eba9033fa1bae
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 last_seen.to_i < (Time.now - 5.minutes).to_i
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
- self.last_seen = DateTime.now
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
@@ -1,3 +1,3 @@
1
1
  module DeviseLastSeen
2
- VERSION = '0.1.0'.freeze
2
+ VERSION = '0.2.0'.freeze
3
3
  end
@@ -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)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: devise_last_seen
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bruno Casali