onlinerbytodd 1.0.0 → 1.0.1
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/README.md +21 -11
- data/lib/onlinerbytodd/model.rb +14 -10
- data/lib/onlinerbytodd/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 28229ce28413c50157265a23a263788d8c2a97ad
|
4
|
+
data.tar.gz: 27839ab8edb3c224a4e7e8866c8270e588ab7e80
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 89b262d399fd48bda0fa4f314026e5a6716e75c7f1eaca4f829d1f33db4232530c296b4557d2e9a087f8be58f2a2eaa4604b58fbb0ecccd89312ad7c8adcdff9
|
7
|
+
data.tar.gz: 6bdb92a734c71bf208647394de78d9cb743d376255bfa200a1b1110de1776757a0a1102113b463591dbf8dc83d98ce340eec3657f3b46c84f57da406be97eb73
|
data/README.md
CHANGED
@@ -20,6 +20,13 @@ Next you have to run this to make it install the initializer
|
|
20
20
|
|
21
21
|
$ rails g onlinerbytodd:install
|
22
22
|
|
23
|
+
*Note: if you are doing this on a Heroku server run the following command:
|
24
|
+
|
25
|
+
$ heroku run rails g onlinerbytodd:install
|
26
|
+
|
27
|
+
Do not do a run:detached as it prompts you and you will have to manually
|
28
|
+
terminate the process if you run:detached.
|
29
|
+
|
23
30
|
## Usage
|
24
31
|
|
25
32
|
For using functionality add to ApplicationControler:
|
@@ -40,9 +47,12 @@ To see if a user is online you would run something like this:
|
|
40
47
|
|
41
48
|
User.online.include?(user)
|
42
49
|
|
43
|
-
|
44
|
-
15 seconds
|
45
|
-
this
|
50
|
+
Now you can override the default time to check for user activity. It defaults
|
51
|
+
to 15 seconds (i.e. if the user hasn't done anything for 15 seconds they are
|
52
|
+
not considered online). To override this with say 30 seconds you would do the
|
53
|
+
following:
|
54
|
+
|
55
|
+
User.online(30).include?(user)
|
46
56
|
|
47
57
|
I have also modified the code to work more easily with RedisToGo on Heroku.
|
48
58
|
It now works with RedisToGo on Heroku, it needed the password to be parsed,
|
@@ -50,14 +60,14 @@ now it is.
|
|
50
60
|
|
51
61
|
Tasks for future versions:
|
52
62
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
63
|
+
- [x] Allow users to customize the time for a user to be considered online
|
64
|
+
- [x] Make the onlinerbytodd.rb accept a variable for the time
|
65
|
+
- [x] Make that variable default to 15 seconds if not set
|
66
|
+
- [x] Provide instructions for how a user can override the default
|
67
|
+
- [ ] Have software ignore Redis errors so if this gem doesn't work it doesn't break the app
|
68
|
+
- [ ] Add an exception for if REDIS isn't set or is unreachable
|
69
|
+
- [ ] Have onlinerbytodd notify the user (either a flash message or an e-mail)
|
70
|
+
- [ ] make that notification message alterable (and the destination alterable)
|
61
71
|
|
62
72
|
* This is mainly because if you hit your limit for your current RedisToGo plan or other applicable plan it would currently break the whole app
|
63
73
|
* If we have this gem send the user an e-mail or something, or set a flash message, then the user can know what is going on and can fix it
|
data/lib/onlinerbytodd/model.rb
CHANGED
@@ -4,22 +4,26 @@ module Devise
|
|
4
4
|
extend ActiveSupport::Concern
|
5
5
|
|
6
6
|
module ClassMethods
|
7
|
-
def online
|
8
|
-
|
9
|
-
|
7
|
+
def online(time=15)
|
8
|
+
if defined?(REDIS)
|
9
|
+
array_ids = []
|
10
|
+
online_array = REDIS.hgetall "o_#{self.to_s.downcase.pluralize}"
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
online_array.each do |k, v|
|
13
|
+
if (Time.now - v.to_time <= time)
|
14
|
+
array_ids << k.to_i
|
15
|
+
end
|
16
|
+
end
|
16
17
|
|
17
|
-
|
18
|
+
self.find( array_ids )
|
19
|
+
end
|
18
20
|
end
|
19
21
|
end
|
20
22
|
|
21
23
|
def track
|
22
|
-
REDIS
|
24
|
+
if defined?(REDIS)
|
25
|
+
REDIS.mapped_hmset "o_#{self.class.to_s.downcase.pluralize}", { id.to_s => "#{Time.now}" }
|
26
|
+
end
|
23
27
|
end
|
24
28
|
end
|
25
29
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: onlinerbytodd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Todd Nestor
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-10-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|