rego-devise-lastseenable 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +14 -0
- data/LICENSE.txt +20 -0
- data/README.md +56 -0
- data/Rakefile +49 -0
- data/VERSION +1 -0
- data/lib/generators/rego-devise-lastseenable/rego-devise-lastseenable_generator.rb +31 -0
- data/lib/generators/rego-devise-lastseenable/templates/migration.rb +9 -0
- data/lib/rego-devise-lastseenable.rb +12 -0
- data/lib/rego-devise-lastseenable/devise_config.rb +5 -0
- data/lib/rego-devise-lastseenable/hooks.rb +5 -0
- data/lib/rego-devise-lastseenable/model.rb +19 -0
- data/lib/rego-devise-lastseenable/rails.rb +6 -0
- data/rego-devise-lastseenable.gemspec +68 -0
- data/spec/rego-devise-lastseenable_spec.rb +7 -0
- data/spec/spec_helper.rb +12 -0
- metadata +157 -0
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
# Add dependencies to develop your gem here.
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
group :development do
|
9
|
+
gem "rdoc"
|
10
|
+
gem "rspec", "~> 2.3.0"
|
11
|
+
gem "bundler", "~> 1.0.0"
|
12
|
+
gem "jeweler", "~> 1.6.4"
|
13
|
+
gem "rcov", ">= 0"
|
14
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 Alex
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
# rego-devise-lastseenable
|
2
|
+
|
3
|
+
Ensure that devise will update a last_seen_at flag on the model whenever user is authed.
|
4
|
+
|
5
|
+
# Usage
|
6
|
+
|
7
|
+
Generate migration that adds `:last_seen_at column` to your model using generator:
|
8
|
+
|
9
|
+
rails g devise_lastseenable User
|
10
|
+
|
11
|
+
Or add migration manually:
|
12
|
+
|
13
|
+
class DeviseAddLastseenableAccount < ActiveRecord::Migration
|
14
|
+
def self.up
|
15
|
+
add_column :accounts, :last_seen_at, :datetime
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.down
|
19
|
+
remove_column :accounts, :last_seen_at
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
In your model, add `:lastseenable` as such:
|
25
|
+
|
26
|
+
class User < ActiveRecord::Base
|
27
|
+
|
28
|
+
devise ..., :lastseenable
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
In devise.rb you can configure `lastseenable_interval` parameter (defaults to 5 minutes), which defines the interval (in minutes) to update `last_seent_at` attribute of your model:
|
34
|
+
|
35
|
+
# Configure lastseenable interval to update last_seen_at every two minutes
|
36
|
+
config.lastseenable_interval = 2
|
37
|
+
|
38
|
+
|
39
|
+
# Release notes
|
40
|
+
|
41
|
+
* 0.1.0 - first release
|
42
|
+
|
43
|
+
# Contributing to rego-ruby-ext
|
44
|
+
|
45
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
46
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
47
|
+
* Fork the project
|
48
|
+
* Start a feature/bugfix branch
|
49
|
+
* Commit and push until you are happy with your contribution
|
50
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
51
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
52
|
+
|
53
|
+
# Copyright
|
54
|
+
|
55
|
+
Copyright (c) 2011 Alex Tkachev. See LICENSE.txt for
|
56
|
+
further details.
|
data/Rakefile
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "rego-devise-lastseenable"
|
18
|
+
gem.homepage = "http://github.com/alextk/rego-devise-lastseenable"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{Ensure that devise will update a last_seen_at flag on the model whenever user is authed}
|
21
|
+
gem.description = %Q{Ensure that devise will update a last_seen_at flag on the model whenever user is authed}
|
22
|
+
gem.email = "tkachev.alex@gmail.com"
|
23
|
+
gem.authors = ["Alex"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rspec/core'
|
29
|
+
require 'rspec/core/rake_task'
|
30
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
31
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
32
|
+
end
|
33
|
+
|
34
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
35
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
36
|
+
spec.rcov = true
|
37
|
+
end
|
38
|
+
|
39
|
+
task :default => :spec
|
40
|
+
|
41
|
+
require 'rdoc/task'
|
42
|
+
RDoc::Task.new do |rdoc|
|
43
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
44
|
+
|
45
|
+
rdoc.rdoc_dir = 'rdoc'
|
46
|
+
rdoc.title = "rego-devise-lastseenable #{version}"
|
47
|
+
rdoc.rdoc_files.include('README*')
|
48
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
49
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'rails/generators/migration'
|
2
|
+
|
3
|
+
class DeviseLastseenableGenerator < Rails::Generators::NamedBase
|
4
|
+
include Rails::Generators::Migration
|
5
|
+
|
6
|
+
def self.source_root
|
7
|
+
@_devise_source_root ||= File.expand_path("../templates", __FILE__)
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.orm_has_migration?
|
11
|
+
Rails::Generators.options[:rails][:orm] == :active_record
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.next_migration_number(dirname)
|
15
|
+
if ActiveRecord::Base.timestamped_migrations
|
16
|
+
Time.now.utc.strftime("%Y%m%d%H%M%S")
|
17
|
+
else
|
18
|
+
"%.3d" % (current_migration_number(dirname) + 1)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class_option :orm
|
23
|
+
class_option :migration, :type => :boolean, :default => orm_has_migration?
|
24
|
+
|
25
|
+
|
26
|
+
def create_migration_file
|
27
|
+
migration_template 'migration.rb', "db/migrate/devise_add_lastseenable_#{name.downcase}.rb"
|
28
|
+
end
|
29
|
+
|
30
|
+
protected
|
31
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
unless defined?(Devise)
|
2
|
+
require 'devise'
|
3
|
+
end
|
4
|
+
require 'rego-devise-lastseenable'
|
5
|
+
require 'rego-devise-lastseenable/devise_config'
|
6
|
+
|
7
|
+
Devise.add_module :lastseenable, :model => 'rego-devise-lastseenable/model'
|
8
|
+
|
9
|
+
module DeviseLastseenable
|
10
|
+
end
|
11
|
+
|
12
|
+
require 'rego-devise-lastseenable/rails'
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'rego-devise-lastseenable/hooks'
|
2
|
+
|
3
|
+
module Devise
|
4
|
+
module Models
|
5
|
+
module Lastseenable
|
6
|
+
def stamp!
|
7
|
+
interval = self.class.lastseenable_interval
|
8
|
+
if self.last_seen_at.to_i < (Time.now - interval.minutes).to_i
|
9
|
+
self.last_seen_at = DateTime.now
|
10
|
+
self.save!
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
module ClassMethods
|
15
|
+
Devise::Models.config(self, :lastseenable_interval)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "rego-devise-lastseenable"
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Alex"]
|
12
|
+
s.date = "2012-01-29"
|
13
|
+
s.description = "Ensure that devise will update a last_seen_at flag on the model whenever user is authed"
|
14
|
+
s.email = "tkachev.alex@gmail.com"
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.md"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".rspec",
|
22
|
+
"Gemfile",
|
23
|
+
"LICENSE.txt",
|
24
|
+
"README.md",
|
25
|
+
"Rakefile",
|
26
|
+
"VERSION",
|
27
|
+
"lib/generators/rego-devise-lastseenable/rego-devise-lastseenable_generator.rb",
|
28
|
+
"lib/generators/rego-devise-lastseenable/templates/migration.rb",
|
29
|
+
"lib/rego-devise-lastseenable.rb",
|
30
|
+
"lib/rego-devise-lastseenable/devise_config.rb",
|
31
|
+
"lib/rego-devise-lastseenable/hooks.rb",
|
32
|
+
"lib/rego-devise-lastseenable/model.rb",
|
33
|
+
"lib/rego-devise-lastseenable/rails.rb",
|
34
|
+
"rego-devise-lastseenable.gemspec",
|
35
|
+
"spec/rego-devise-lastseenable_spec.rb",
|
36
|
+
"spec/spec_helper.rb"
|
37
|
+
]
|
38
|
+
s.homepage = "http://github.com/alextk/rego-devise-lastseenable"
|
39
|
+
s.licenses = ["MIT"]
|
40
|
+
s.require_paths = ["lib"]
|
41
|
+
s.rubygems_version = "1.8.10"
|
42
|
+
s.summary = "Ensure that devise will update a last_seen_at flag on the model whenever user is authed"
|
43
|
+
|
44
|
+
if s.respond_to? :specification_version then
|
45
|
+
s.specification_version = 3
|
46
|
+
|
47
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
48
|
+
s.add_development_dependency(%q<rdoc>, [">= 0"])
|
49
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
|
50
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
51
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
|
52
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
53
|
+
else
|
54
|
+
s.add_dependency(%q<rdoc>, [">= 0"])
|
55
|
+
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
56
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
57
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
58
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
59
|
+
end
|
60
|
+
else
|
61
|
+
s.add_dependency(%q<rdoc>, [">= 0"])
|
62
|
+
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
63
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
64
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
65
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'rego-devise-lastseenable'
|
5
|
+
|
6
|
+
# Requires supporting files with custom matchers and macros, etc,
|
7
|
+
# in ./support/ and its subdirectories.
|
8
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
|
12
|
+
end
|
metadata
ADDED
@@ -0,0 +1,157 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rego-devise-lastseenable
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Alex
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2012-01-29 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
22
|
+
none: false
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
hash: 3
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
version: "0"
|
30
|
+
name: rdoc
|
31
|
+
prerelease: false
|
32
|
+
type: :development
|
33
|
+
requirement: *id001
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
36
|
+
none: false
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
hash: 3
|
41
|
+
segments:
|
42
|
+
- 2
|
43
|
+
- 3
|
44
|
+
- 0
|
45
|
+
version: 2.3.0
|
46
|
+
name: rspec
|
47
|
+
prerelease: false
|
48
|
+
type: :development
|
49
|
+
requirement: *id002
|
50
|
+
- !ruby/object:Gem::Dependency
|
51
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ~>
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
hash: 23
|
57
|
+
segments:
|
58
|
+
- 1
|
59
|
+
- 0
|
60
|
+
- 0
|
61
|
+
version: 1.0.0
|
62
|
+
name: bundler
|
63
|
+
prerelease: false
|
64
|
+
type: :development
|
65
|
+
requirement: *id003
|
66
|
+
- !ruby/object:Gem::Dependency
|
67
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ~>
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
hash: 7
|
73
|
+
segments:
|
74
|
+
- 1
|
75
|
+
- 6
|
76
|
+
- 4
|
77
|
+
version: 1.6.4
|
78
|
+
name: jeweler
|
79
|
+
prerelease: false
|
80
|
+
type: :development
|
81
|
+
requirement: *id004
|
82
|
+
- !ruby/object:Gem::Dependency
|
83
|
+
version_requirements: &id005 !ruby/object:Gem::Requirement
|
84
|
+
none: false
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
hash: 3
|
89
|
+
segments:
|
90
|
+
- 0
|
91
|
+
version: "0"
|
92
|
+
name: rcov
|
93
|
+
prerelease: false
|
94
|
+
type: :development
|
95
|
+
requirement: *id005
|
96
|
+
description: Ensure that devise will update a last_seen_at flag on the model whenever user is authed
|
97
|
+
email: tkachev.alex@gmail.com
|
98
|
+
executables: []
|
99
|
+
|
100
|
+
extensions: []
|
101
|
+
|
102
|
+
extra_rdoc_files:
|
103
|
+
- LICENSE.txt
|
104
|
+
- README.md
|
105
|
+
files:
|
106
|
+
- .document
|
107
|
+
- .rspec
|
108
|
+
- Gemfile
|
109
|
+
- LICENSE.txt
|
110
|
+
- README.md
|
111
|
+
- Rakefile
|
112
|
+
- VERSION
|
113
|
+
- lib/generators/rego-devise-lastseenable/rego-devise-lastseenable_generator.rb
|
114
|
+
- lib/generators/rego-devise-lastseenable/templates/migration.rb
|
115
|
+
- lib/rego-devise-lastseenable.rb
|
116
|
+
- lib/rego-devise-lastseenable/devise_config.rb
|
117
|
+
- lib/rego-devise-lastseenable/hooks.rb
|
118
|
+
- lib/rego-devise-lastseenable/model.rb
|
119
|
+
- lib/rego-devise-lastseenable/rails.rb
|
120
|
+
- rego-devise-lastseenable.gemspec
|
121
|
+
- spec/rego-devise-lastseenable_spec.rb
|
122
|
+
- spec/spec_helper.rb
|
123
|
+
homepage: http://github.com/alextk/rego-devise-lastseenable
|
124
|
+
licenses:
|
125
|
+
- MIT
|
126
|
+
post_install_message:
|
127
|
+
rdoc_options: []
|
128
|
+
|
129
|
+
require_paths:
|
130
|
+
- lib
|
131
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
132
|
+
none: false
|
133
|
+
requirements:
|
134
|
+
- - ">="
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
hash: 3
|
137
|
+
segments:
|
138
|
+
- 0
|
139
|
+
version: "0"
|
140
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
141
|
+
none: false
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
hash: 3
|
146
|
+
segments:
|
147
|
+
- 0
|
148
|
+
version: "0"
|
149
|
+
requirements: []
|
150
|
+
|
151
|
+
rubyforge_project:
|
152
|
+
rubygems_version: 1.8.10
|
153
|
+
signing_key:
|
154
|
+
specification_version: 3
|
155
|
+
summary: Ensure that devise will update a last_seen_at flag on the model whenever user is authed
|
156
|
+
test_files: []
|
157
|
+
|