onliner 0.0.4 → 1.1.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: 815e5bc8ff9054e693bfc0f452f419dce638055f
4
- data.tar.gz: d8448f15ce046d696a502078a401dda2ba8955a8
3
+ metadata.gz: c719b6058b329be36c1bafccd4b81726f75f6cc8
4
+ data.tar.gz: e0117d25f0d5d2221944307df968ce1056c56137
5
5
  SHA512:
6
- metadata.gz: 9431a99ececb41636ec4596f5d44dbd9abbbc30a80967b16917b05b8661bc8b53a7712797c025a6727a8cd95769d9a7e77274ad489cfa9d33e0a88f62e8b01ed
7
- data.tar.gz: 9a5726cc5886146746986963a562a8b28cd75282d285ff5720dd990adbb37a71f110578b116c31f62433b152a1ea321f5a9d2e17d9dc8c3550c4b2fb866f3899
6
+ metadata.gz: 4fb7dcdf1c498e82586ee5a15d52ee399b78bbcb5264668fadb4d492b3247d9eb151f66aeac9a66dfab6c8c3ec8efc4a9b5891baf5c5a49c04d66a607dc694be
7
+ data.tar.gz: f2cb05db60dd8d2c0b2e4058eeee16c497884080ed698ea0421f5f87d67b4b2e0ca9dc88f83c312790a078ca81edc104789d2d22aa2a2cab1278fb9fd21c689b
@@ -1,4 +1,4 @@
1
- Copyright (c) 2014 kbokhonko
1
+ Copyright (c) 2014 Todd Nestor
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -1,6 +1,4 @@
1
- # Onliner
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
- For installing gem to your app run:
14
+ Next you have to run this to make it install the initializer
15
+
16
+ $ rails g onliner:install
17
17
 
18
- $ rails g onliner:install
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 :lastseenable as such:
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 ..., :lastseenable
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;
@@ -6,4 +6,4 @@ else
6
6
  uri = URI.parse(ENV["REDISTOGO_URL"])
7
7
  end
8
8
 
9
- REDIS = Redis.new(:host => uri.host, :port => uri.port)
9
+ REDIS = Redis.new(:host => uri.host, :port => uri.port, :password => uri.password)
@@ -4,23 +4,27 @@ 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 <= 300)
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
- end
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
26
- end
30
+ end
@@ -1,3 +1,3 @@
1
1
  module Onliner
2
- VERSION = "0.0.4"
2
+ VERSION = "1.1.1"
3
3
  end
@@ -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: 0.0.4
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-03-26 00:00:00.000000000 Z
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: []