onlinerbytodd 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 68df277dd975a882ee28bb653d3652463aadd61b
4
- data.tar.gz: e564d0d9df4310806efed938c71b3b1f1dc74be9
3
+ metadata.gz: 28229ce28413c50157265a23a263788d8c2a97ad
4
+ data.tar.gz: 27839ab8edb3c224a4e7e8866c8270e588ab7e80
5
5
  SHA512:
6
- metadata.gz: 9d931a3b2fae2e8468e58bb65e203f237f76d98f3b722eab4dd1c0fdadd719758639fd25b6d638b40f2b0f382e0bac41d536398b9587105633466b1923f41819
7
- data.tar.gz: df39fca3d72eca232a9ce3376cc8c7c2ec7dfb338e42d92776836848f180a599ad57c219d612a9e4d3bea3eb9ee399fb246fb233206ff7a25079632e2357929a
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
- In this version I have modified the time to consider a user still online to
44
- 15 seconds, previously it was 300 seconds. In a future version I will make
45
- this more easily customizable by users.
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
- [] Allow users to customize the time for a user to be considered online
54
- [] Make the onlinerbytodd.rb accept a variable for the time
55
- [] Make that variable default to 15 seconds if not set
56
- [] Provide instructions for how a user can override the default
57
- [] Have software ignore Redis errors so if this gem doesn't work it doesn't break the app
58
- [] Add an exception for if REDIS isn't set or is unreachable
59
- [] Have onlinerbytodd notify the user (either a flash message or an e-mail)
60
- [] make that notification message alterable (and the destination alterable)
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
@@ -4,22 +4,26 @@ module Devise
4
4
  extend ActiveSupport::Concern
5
5
 
6
6
  module ClassMethods
7
- def online
8
- array_ids = []
9
- online_array = REDIS.hgetall "o_#{self.to_s.downcase.pluralize}"
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
- online_array.each do |k, v|
12
- if (Time.now - v.to_time <= 15)
13
- array_ids << k.to_i
14
- end
15
- end
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
- self.find( array_ids )
18
+ self.find( array_ids )
19
+ end
18
20
  end
19
21
  end
20
22
 
21
23
  def track
22
- REDIS.mapped_hmset "o_#{self.class.to_s.downcase.pluralize}", { id.to_s => "#{Time.now}" }
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
@@ -1,3 +1,3 @@
1
1
  module Onlinerbytodd
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  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.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-06-07 00:00:00.000000000 Z
11
+ date: 2014-10-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler