onlinerbytodd 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 68df277dd975a882ee28bb653d3652463aadd61b
4
+ data.tar.gz: e564d0d9df4310806efed938c71b3b1f1dc74be9
5
+ SHA512:
6
+ metadata.gz: 9d931a3b2fae2e8468e58bb65e203f237f76d98f3b722eab4dd1c0fdadd719758639fd25b6d638b40f2b0f382e0bac41d536398b9587105633466b1923f41819
7
+ data.tar.gz: df39fca3d72eca232a9ce3376cc8c7c2ec7dfb338e42d92776836848f180a599ad57c219d612a9e4d3bea3eb9ee399fb246fb233206ff7a25079632e2357929a
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in onliner.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Todd Nestor
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,70 @@
1
+ # Onlinerbytodd
2
+
3
+ * Built off of the onliner gem, but renamed so I could deploy it on rubygems,
4
+ * this version plays nice with Heroku and RedisToGo, as of June 6, 2014.
5
+
6
+
7
+ Gem for Rails application - provides you list of online users (for authentication gem 'devise')
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ gem 'onlinerbytodd'
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Next you have to run this to make it install the initializer
20
+
21
+ $ rails g onlinerbytodd:install
22
+
23
+ ## Usage
24
+
25
+ For using functionality add to ApplicationControler:
26
+
27
+ before_filter { |c| current_user.track unless current_user.nil?}
28
+
29
+ and In your model, add :onliner-by-todd to the current devise line at the end:
30
+
31
+ class User < ActiveRecord::Base
32
+ devise ..., :onlinerbytodd
33
+ end
34
+
35
+ Helper for online users list (for the whole list, not just an individual):
36
+
37
+ Model.online, e.g. User.online, Admin.online
38
+
39
+ To see if a user is online you would run something like this:
40
+
41
+ User.online.include?(user)
42
+
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.
46
+
47
+ I have also modified the code to work more easily with RedisToGo on Heroku.
48
+ It now works with RedisToGo on Heroku, it needed the password to be parsed,
49
+ now it is.
50
+
51
+ Tasks for future versions:
52
+
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)
61
+
62
+ * 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
+ * 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
64
+
65
+ ## Requirement
66
+
67
+ * Redis; this gem will make sure the dependencies get installed but you have
68
+ to make sure you have it on your server, for Heroku I recommend RedisToGo.
69
+
70
+ * Devise;
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,12 @@
1
+ require "rails"
2
+
3
+ module Onlinerbytodd
4
+ class InstallGenerator < Rails::Generators::Base
5
+ source_root File.expand_path('../../templates', __FILE__)
6
+
7
+ def copy_files
8
+ create_file "config/initializers/onlinerbytodd.rb"
9
+ copy_file "onlinerbytodd.rb", "config/initializers/onlinerbytodd.rb"
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,9 @@
1
+ require "redis"
2
+
3
+ if ( Rails.env.development? || Rails.env.test? )
4
+ uri = URI.parse("localhost:6379")
5
+ else
6
+ uri = URI.parse(ENV["REDISTOGO_URL"])
7
+ end
8
+
9
+ REDIS = Redis.new(:host => uri.host, :port => uri.port, :password => uri.password)
@@ -0,0 +1,26 @@
1
+ module Devise
2
+ module Models
3
+ module Onlinerbytodd
4
+ extend ActiveSupport::Concern
5
+
6
+ module ClassMethods
7
+ def online
8
+ array_ids = []
9
+ online_array = REDIS.hgetall "o_#{self.to_s.downcase.pluralize}"
10
+
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
16
+
17
+ self.find( array_ids )
18
+ end
19
+ end
20
+
21
+ def track
22
+ REDIS.mapped_hmset "o_#{self.class.to_s.downcase.pluralize}", { id.to_s => "#{Time.now}" }
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,3 @@
1
+ module Onlinerbytodd
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,13 @@
1
+ require "onlinerbytodd/version"
2
+
3
+ unless defined?(Devise)
4
+ require 'devise'
5
+ end
6
+
7
+ require 'onlinerbytodd'
8
+
9
+ Devise.add_module :onlinerbytodd, :model => 'onlinerbytodd/model'
10
+
11
+ module Onlinerbytodd
12
+ end
13
+
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'onlinerbytodd/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "onlinerbytodd"
8
+ spec.platform = Gem::Platform::RUBY
9
+ spec.version = Onlinerbytodd::VERSION
10
+ spec.authors = ["Todd Nestor"]
11
+ spec.email = ["todd.nestor@gmail.com"]
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'), built off of the onliner gem}
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+
24
+ spec.add_dependency('redis', '~> 3.0.6')
25
+ spec.add_dependency "redis-namespace", ">= 1.3.0"
26
+ end
metadata ADDED
@@ -0,0 +1,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: onlinerbytodd
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Todd Nestor
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-06-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: redis
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 3.0.6
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 3.0.6
55
+ - !ruby/object:Gem::Dependency
56
+ name: redis-namespace
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 1.3.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: 1.3.0
69
+ description: Gem for Rails application - provides you list of online users (for authentication
70
+ gem 'devise')
71
+ email:
72
+ - todd.nestor@gmail.com
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - lib/generators/onlinerbytodd/install_generator.rb
83
+ - lib/generators/templates/onlinerbytodd.rb
84
+ - lib/onlinerbytodd.rb
85
+ - lib/onlinerbytodd/model.rb
86
+ - lib/onlinerbytodd/version.rb
87
+ - onlinerbytodd.gemspec
88
+ homepage:
89
+ licenses:
90
+ - MIT
91
+ metadata: {}
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubyforge_project:
108
+ rubygems_version: 2.2.2
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: Gem for Rails application - provides you list of online users (for authentication
112
+ gem 'devise'), built off of the onliner gem
113
+ test_files: []