devise_traceable 0.0.2

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.
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'rails', "3.0.0.beta4"
4
+ gem 'mysql'
5
+ gem 'warden'
6
+ gem 'devise'
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2010 mobiThought
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.rdoc ADDED
@@ -0,0 +1,34 @@
1
+ = devise_traceable
2
+
3
+ It adds support to devise[http://github.com/plataformatec/devise] for traceing.
4
+
5
+ == Installation
6
+
7
+ All gems are on gemcutter, so you need to add gemcutter to your sources if you haven’t yet:
8
+
9
+ sudo gem sources -a http://gemcutter.org/
10
+
11
+ Install devise_traceable gem, it should install dependencies (such as devise and warden):
12
+
13
+ sudo gem install devise_traceable
14
+
15
+ Configure devise_traceable inside your app (and warden and devise if you weren't using them):
16
+
17
+ config.gem 'warden'
18
+ config.gem 'devise'
19
+ config.gem 'devise_traceable'
20
+
21
+ == Note on Patches/Pull Requests
22
+
23
+ * Fork the project.
24
+ * Make your feature addition or bug fix.
25
+ * Add tests for it. This is important so I don't break it in a
26
+ future version unintentionally.
27
+ * Commit, do not mess with rakefile, version, or history.
28
+ (if you want to have your own version, that is fine but
29
+ bump version in a commit by itself I can ignore when I pull)
30
+ * Send me a pull request. Bonus points for topic branches.
31
+
32
+ == Copyright
33
+
34
+ Copyright (c) 2010 mobiThought. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,44 @@
1
+ # encoding: UTF-8
2
+ require 'rake'
3
+ require 'rake/rdoctask'
4
+ require 'rake/gempackagetask'
5
+ require 'rake/testtask'
6
+
7
+ Rake::TestTask.new(:test) do |t|
8
+ t.libs << 'lib'
9
+ t.libs << 'test'
10
+ t.pattern = 'test/**/*_test.rb'
11
+ t.verbose = false
12
+ end
13
+
14
+ task :default => :test
15
+
16
+ Rake::RDocTask.new(:rdoc) do |rdoc|
17
+ rdoc.rdoc_dir = 'rdoc'
18
+ rdoc.title = 'DeviseTraceable'
19
+ rdoc.options << '--line-numbers' << '--inline-source'
20
+ rdoc.rdoc_files.include('README.rdoc')
21
+ rdoc.rdoc_files.include('lib/**/*.rb')
22
+ end
23
+
24
+ spec = Gem::Specification.new do |s|
25
+ s.name = "devise_traceable"
26
+ s.summary = "Devise Traceable For Traceing Devise Models"
27
+ s.description = "Devise Traceable For Traceing Devise Models Logins and Logouts in separate model table"
28
+ s.files = FileList["[A-Z]*", "{lib}/**/*"]
29
+ s.require_paths = ["lib"]
30
+ s.version = "0.0.2"
31
+ s.email = "sbertel@mobithought.com"
32
+ s.homepage = "http://github.com/shenoudab/devise_traceable"
33
+ s.author = 'Shenouda Bertel'
34
+ s.add_dependency("warden")
35
+ s.add_dependency("devise")
36
+ end
37
+
38
+ Rake::GemPackageTask.new(spec) do |pkg|
39
+ end
40
+
41
+ desc "Install the gem #{spec.name}-#{spec.version}.gem"
42
+ task :install do
43
+ system("gem install pkg/#{spec.name}-#{spec.version}.gem --no-ri --no-rdoc")
44
+ end
@@ -0,0 +1,18 @@
1
+ # After each sign in, sign out.
2
+ # This is only triggered when the user is explicitly set (with set_user)
3
+ # and on authentication. Retrieving the user from session (:fetch) does
4
+ # not trigger it.
5
+
6
+ Warden::Manager.after_set_user :except => :fetch do |record, warden, options|
7
+ puts record
8
+ if record.respond_to?(:insert_login!) #&& warden.authenticated?(options[:scope])
9
+ record.insert_login!(warden.request)
10
+ end
11
+ end
12
+
13
+ Warden::Manager.before_logout do |record, warden, opts|
14
+ puts record
15
+ if record.respond_to?(:update_logout!)
16
+ record.update_logout!(warden.request)
17
+ end
18
+ end
@@ -0,0 +1,29 @@
1
+ require 'devise_traceable/hooks/traceable'
2
+
3
+ module Devise
4
+ module Models
5
+ # Trace information about your user sign in. It tracks the following columns:
6
+
7
+ # * resource_id
8
+ # * sign_in_at
9
+ # * sign_out_at
10
+ # * time
11
+ #
12
+
13
+ module Traceable
14
+ def insert_login!(request)
15
+ new_current = Time.now
16
+ self.sign_in_at = new_current
17
+ save(:validate => false)
18
+ end
19
+
20
+ def update_logout!(request)
21
+ new_current = Time.now
22
+ self.sign_out_at = new_current
23
+ time = self.sign_out_at - self.sign_in_at
24
+ self.time = time
25
+ save(:validate => false)
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,7 @@
1
+ require 'devise_traceable'
2
+
3
+ module DeviseTraceable
4
+ class Engine < ::Rails::Engine
5
+ engine_name :devise_taceable
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ module DeviseTraceable
2
+ VERSION = "0.0.2".freeze
3
+ end
@@ -0,0 +1,10 @@
1
+ unless defined?(Devise)
2
+ require 'devise'
3
+ end
4
+
5
+ Devise.add_module :traceable, :model => 'devise_traceable/model'
6
+
7
+ module DeviseTraceable
8
+ end
9
+
10
+ require 'devise_traceable/rails'
@@ -0,0 +1,31 @@
1
+ require 'rails/generators/migration'
2
+
3
+ class DeviseTraceableGenerator < Rails::Generators::NamedBase
4
+ include Rails::Generators::Migration
5
+
6
+ desc "Generates a model with the given NAME (if one does not exist) with devise " <<
7
+ "configuration plus a migration file and devise routes."
8
+
9
+ def self.source_root
10
+ @_devise_source_root ||= File.expand_path("../templates", __FILE__)
11
+ end
12
+
13
+ def self.orm_has_migration?
14
+ Rails::Generators.options[:rails][:orm] == :active_record
15
+ end
16
+
17
+ def self.next_migration_number(dirname)
18
+ if ActiveRecord::Base.timestamped_migrations
19
+ Time.now.utc.strftime("%Y%m%d%H%M%S")
20
+ else
21
+ "%.3d" % (current_migration_number(dirname) + 1)
22
+ end
23
+ end
24
+
25
+ class_option :orm
26
+ class_option :migration, :type => :boolean, :default => orm_has_migration?
27
+
28
+ def create_migration_file
29
+ migration_template 'migration.rb', "db/migrate/devise_create_#{name.tableize}_tracing.rb"
30
+ end
31
+ end
@@ -0,0 +1,18 @@
1
+ class DeviseCreate<%= table_name.camelize %>Tracing < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :<%= table_name %>_tracing do |t|
4
+ t.integer :<%= table_name.classify.foreign_key %>
5
+ t.datetime :sign_in_at
6
+ t.datetime :sign_out_at
7
+ #Any additional fields here
8
+
9
+ t.timestamps
10
+ end
11
+
12
+ add_index :<%= table_name %>_tracing, :<%= table_name.classify.foreign_key %>
13
+ end
14
+
15
+ def self.down
16
+ drop_table :<%= table_name %>
17
+ end
18
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: devise_traceable
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 2
9
+ version: 0.0.2
10
+ platform: ruby
11
+ authors:
12
+ - Shenouda Bertel
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-06-17 00:00:00 +03:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: warden
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 0
30
+ version: "0"
31
+ type: :runtime
32
+ version_requirements: *id001
33
+ - !ruby/object:Gem::Dependency
34
+ name: devise
35
+ prerelease: false
36
+ requirement: &id002 !ruby/object:Gem::Requirement
37
+ none: false
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 0
43
+ version: "0"
44
+ type: :runtime
45
+ version_requirements: *id002
46
+ description: Devise Traceable For Traceing Devise Models Logins and Logouts in separate model table
47
+ email: sbertel@mobithought.com
48
+ executables: []
49
+
50
+ extensions: []
51
+
52
+ extra_rdoc_files: []
53
+
54
+ files:
55
+ - MIT-LICENSE
56
+ - Gemfile
57
+ - README.rdoc
58
+ - Rakefile
59
+ - lib/devise_traceable.rb
60
+ - lib/devise_traceable/hooks/traceable.rb
61
+ - lib/devise_traceable/model.rb
62
+ - lib/devise_traceable/version.rb
63
+ - lib/devise_traceable/rails.rb
64
+ - lib/generators/devise_traceable/devise_traceable_generator.rb
65
+ - lib/generators/devise_traceable/templates/migration.rb
66
+ has_rdoc: true
67
+ homepage: http://github.com/shenoudab/devise_traceable
68
+ licenses: []
69
+
70
+ post_install_message:
71
+ rdoc_options: []
72
+
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ none: false
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ segments:
81
+ - 0
82
+ version: "0"
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ segments:
89
+ - 0
90
+ version: "0"
91
+ requirements: []
92
+
93
+ rubyforge_project:
94
+ rubygems_version: 1.3.7
95
+ signing_key:
96
+ specification_version: 3
97
+ summary: Devise Traceable For Traceing Devise Models
98
+ test_files: []
99
+