onliner 0.0.4 → 1.1.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/LICENSE.txt +1 -1
- data/README.md +44 -9
- data/lib/generators/templates/onliner.rb +1 -1
- data/lib/onliner/model.rb +16 -12
- data/lib/onliner/version.rb +1 -1
- data/onliner.gemspec +4 -4
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c719b6058b329be36c1bafccd4b81726f75f6cc8
|
4
|
+
data.tar.gz: e0117d25f0d5d2221944307df968ce1056c56137
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4fb7dcdf1c498e82586ee5a15d52ee399b78bbcb5264668fadb4d492b3247d9eb151f66aeac9a66dfab6c8c3ec8efc4a9b5891baf5c5a49c04d66a607dc694be
|
7
|
+
data.tar.gz: f2cb05db60dd8d2c0b2e4058eeee16c497884080ed698ea0421f5f87d67b4b2e0ca9dc88f83c312790a078ca81edc104789d2d22aa2a2cab1278fb9fd21c689b
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,4 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
|
1
|
+
# onliner
|
4
2
|
Gem for Rails application - provides you list of online users (for authentication gem 'devise')
|
5
3
|
|
6
4
|
## Installation
|
@@ -13,9 +11,16 @@ And then execute:
|
|
13
11
|
|
14
12
|
$ bundle
|
15
13
|
|
16
|
-
|
14
|
+
Next you have to run this to make it install the initializer
|
15
|
+
|
16
|
+
$ rails g onliner:install
|
17
17
|
|
18
|
-
|
18
|
+
*Note: if you are doing this on a Heroku server run the following command:
|
19
|
+
|
20
|
+
$ heroku run rails g onliner:install
|
21
|
+
|
22
|
+
Do not do a run:detached as it prompts you and you will have to manually
|
23
|
+
terminate the process if you run:detached.
|
19
24
|
|
20
25
|
## Usage
|
21
26
|
|
@@ -23,18 +28,48 @@ For using functionality add to ApplicationControler:
|
|
23
28
|
|
24
29
|
before_filter { |c| current_user.track unless current_user.nil?}
|
25
30
|
|
26
|
-
and In your model, add :
|
31
|
+
and In your model, add :onliner-by-todd to the current devise line at the end:
|
27
32
|
|
28
33
|
class User < ActiveRecord::Base
|
29
|
-
devise ..., :
|
34
|
+
devise ..., :onliner
|
30
35
|
end
|
31
36
|
|
32
|
-
Helper for online users list:
|
37
|
+
Helper for online users list (for the whole list, not just an individual):
|
33
38
|
|
34
39
|
Model.online, e.g. User.online, Admin.online
|
35
40
|
|
41
|
+
To see if a user is online you would run something like this:
|
42
|
+
|
43
|
+
User.online.include?(user)
|
44
|
+
|
45
|
+
Now you can override the default time to check for user activity. It defaults
|
46
|
+
to 15 seconds (i.e. if the user hasn't done anything for 15 seconds they are
|
47
|
+
not considered online). To override this with say 30 seconds you would do the
|
48
|
+
following:
|
49
|
+
|
50
|
+
User.online(30).include?(user)
|
51
|
+
|
52
|
+
I have also modified the code to work more easily with RedisToGo on Heroku.
|
53
|
+
It now works with RedisToGo on Heroku, it needed the password to be parsed,
|
54
|
+
now it is.
|
55
|
+
|
56
|
+
Tasks for future versions:
|
57
|
+
|
58
|
+
- [x] Allow users to customize the time for a user to be considered online
|
59
|
+
- [x] Make the onliner.rb accept a variable for the time
|
60
|
+
- [x] Make that variable default to 15 seconds if not set
|
61
|
+
- [x] Provide instructions for how a user can override the default
|
62
|
+
- [ ] Have software ignore Redis errors so if this gem doesn't work it doesn't break the app
|
63
|
+
- [ ] Add an exception for if REDIS isn't set or is unreachable
|
64
|
+
- [ ] Have onliner notify the user (either a flash message or an e-mail)
|
65
|
+
- [ ] make that notification message alterable (and the destination alterable)
|
66
|
+
|
67
|
+
* 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
|
68
|
+
* 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
|
69
|
+
|
36
70
|
## Requirement
|
37
71
|
|
38
|
-
* Redis;
|
72
|
+
* Redis; this gem will make sure the dependencies get installed but you have
|
73
|
+
to make sure you have it on your server, for Heroku I recommend RedisToGo.
|
39
74
|
|
40
75
|
* Devise;
|
data/lib/onliner/model.rb
CHANGED
@@ -4,23 +4,27 @@ 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
|
-
end
|
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
|
26
|
-
end
|
30
|
+
end
|
data/lib/onliner/version.rb
CHANGED
data/onliner.gemspec
CHANGED
@@ -7,10 +7,10 @@ Gem::Specification.new do |spec|
|
|
7
7
|
spec.name = "onliner"
|
8
8
|
spec.platform = Gem::Platform::RUBY
|
9
9
|
spec.version = Onliner::VERSION
|
10
|
-
spec.authors = ["kbokhonko"]
|
11
|
-
spec.email = ["kolya.bokhonko@gmail.com"]
|
10
|
+
spec.authors = ["kbokhonko", "Todd Nestor"]
|
11
|
+
spec.email = ["kolya.bokhonko@gmail.com", "todd.nestor@gmail.com"]
|
12
12
|
spec.description = "Gem for Rails application - provides you list of online users (for authentication gem 'devise')"
|
13
|
-
spec.summary = %q{Gem for Rails application - provides you list of online users (for authentication gem 'devise')}
|
13
|
+
spec.summary = %q{Gem for Rails application - provides you list of online users (for authentication gem 'devise'), built off of the onliner gem}
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
16
|
spec.files = `git ls-files`.split($/)
|
@@ -23,4 +23,4 @@ Gem::Specification.new do |spec|
|
|
23
23
|
|
24
24
|
spec.add_dependency('redis', '~> 3.0.6')
|
25
25
|
spec.add_dependency "redis-namespace", ">= 1.3.0"
|
26
|
-
end
|
26
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: onliner
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kbokhonko
|
8
|
+
- Todd Nestor
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date: 2014-
|
12
|
+
date: 2014-11-18 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: bundler
|
@@ -70,6 +71,7 @@ description: Gem for Rails application - provides you list of online users (for
|
|
70
71
|
gem 'devise')
|
71
72
|
email:
|
72
73
|
- kolya.bokhonko@gmail.com
|
74
|
+
- todd.nestor@gmail.com
|
73
75
|
executables: []
|
74
76
|
extensions: []
|
75
77
|
extra_rdoc_files: []
|
@@ -109,5 +111,5 @@ rubygems_version: 2.0.3
|
|
109
111
|
signing_key:
|
110
112
|
specification_version: 4
|
111
113
|
summary: Gem for Rails application - provides you list of online users (for authentication
|
112
|
-
gem 'devise')
|
114
|
+
gem 'devise'), built off of the onliner gem
|
113
115
|
test_files: []
|