activitylog 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,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZjUzY2RlY2E0YTRmNWI3ZmUyNDg2YWI4OWZjMmFmZThhN2E1MzJiNw==
5
+ data.tar.gz: !binary |-
6
+ NTZmZTk0ZTMxNDNkNDIxMjg3M2IxYjI5NTdjZjUyOGE1MjY2ZjgyMA==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ NTU1MmRjZWMyMjgzZTA2MzMxMmVhNGIyNzhjNGM2YmM4NzBlNWQ2YzAwODQy
10
+ YzJlMzRhYTA1N2ViMzFlZDE1MGZiYjIzOTdiZWYzMWY1MzMxMDRhZjk1OTQw
11
+ MDU4ZTFlNWQxODY0YmQwODg5NDBmNDQwOTk3OGZlYjg1Mjc4ZTM=
12
+ data.tar.gz: !binary |-
13
+ MzhkNGE3MDU4M2U4ZjdmNDQyNzJiNTk2NTFmNzYxODI2MzA1ZmVhZGVhOTMy
14
+ MGE2MzE4ZjRmOTM5ZmVmYjc2MDg3ZTBhYjNkZTExYzU5MDcyNWU1MTRlZTUw
15
+ ZDkzOGU4MTM4OWU2MjQyMDMxODllZTU3ZjZjMDI1NjNhODA0MGM=
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,12 @@
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 "shoulda", ">= 0"
10
+ gem "bundler", "~> 1.0"
11
+ gem "jeweler", "~> 1.8.7"
12
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,71 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ activesupport (4.0.0)
5
+ i18n (~> 0.6, >= 0.6.4)
6
+ minitest (~> 4.2)
7
+ multi_json (~> 1.3)
8
+ thread_safe (~> 0.1)
9
+ tzinfo (~> 0.3.37)
10
+ addressable (2.3.5)
11
+ atomic (1.1.14)
12
+ builder (3.2.2)
13
+ faraday (0.8.8)
14
+ multipart-post (~> 1.2.0)
15
+ git (1.2.6)
16
+ github_api (0.10.1)
17
+ addressable
18
+ faraday (~> 0.8.1)
19
+ hashie (>= 1.2)
20
+ multi_json (~> 1.4)
21
+ nokogiri (~> 1.5.2)
22
+ oauth2
23
+ hashie (2.0.5)
24
+ highline (1.6.19)
25
+ httpauth (0.2.0)
26
+ i18n (0.6.5)
27
+ jeweler (1.8.8)
28
+ builder
29
+ bundler (~> 1.0)
30
+ git (>= 1.2.5)
31
+ github_api (= 0.10.1)
32
+ highline (>= 1.6.15)
33
+ nokogiri (= 1.5.10)
34
+ rake
35
+ rdoc
36
+ json (1.8.0)
37
+ jwt (0.1.8)
38
+ multi_json (>= 1.5)
39
+ minitest (4.7.5)
40
+ multi_json (1.8.2)
41
+ multi_xml (0.5.5)
42
+ multipart-post (1.2.0)
43
+ nokogiri (1.5.10)
44
+ oauth2 (0.9.2)
45
+ faraday (~> 0.8)
46
+ httpauth (~> 0.2)
47
+ jwt (~> 0.1.4)
48
+ multi_json (~> 1.0)
49
+ multi_xml (~> 0.5)
50
+ rack (~> 1.2)
51
+ rack (1.5.2)
52
+ rake (10.1.0)
53
+ rdoc (3.12.2)
54
+ json (~> 1.4)
55
+ shoulda (3.5.0)
56
+ shoulda-context (~> 1.0, >= 1.0.1)
57
+ shoulda-matchers (>= 1.4.1, < 3.0)
58
+ shoulda-context (1.1.5)
59
+ shoulda-matchers (2.4.0)
60
+ activesupport (>= 3.0.0)
61
+ thread_safe (0.1.3)
62
+ atomic
63
+ tzinfo (0.3.38)
64
+
65
+ PLATFORMS
66
+ ruby
67
+
68
+ DEPENDENCIES
69
+ bundler (~> 1.0)
70
+ jeweler (~> 1.8.7)
71
+ shoulda
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2013 Jon Erik Suero
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.markdown ADDED
@@ -0,0 +1,39 @@
1
+ # Activity Log
2
+
3
+ Activity Log provides the ability to track model and controller activity in your app.
4
+
5
+ ## How to Use
6
+
7
+ First run the generator the create the required migrations and initializers:
8
+
9
+ $ rails generate activity_log
10
+
11
+ Then migrate the database:
12
+
13
+ $ rake db:migrate
14
+
15
+ To log a model's activity, add the following line to the class:
16
+
17
+ log_model_activity
18
+
19
+ To log a controller's activity, add the follow line to the controller:
20
+
21
+ log_controller_activity
22
+
23
+ Data can be accessed using the ActivityLog Active Record class.
24
+
25
+ ## Contributing to Activity Log
26
+
27
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
28
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
29
+ * Fork the project.
30
+ * Start a feature/bugfix branch.
31
+ * Commit and push until you are happy with your contribution.
32
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
33
+ * 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.
34
+
35
+ ## Copyright
36
+
37
+ Copyright (c) 2013 Jon Erik Suero. See LICENSE.txt for
38
+ further details.
39
+
data/Rakefile ADDED
@@ -0,0 +1,45 @@
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 = "activitylog"
18
+ gem.homepage = "http://github.com/JonErikDSuero/activitylog"
19
+ gem.license = "MIT"
20
+ gem.summary = "Provides Activity Log functionality to your code"
21
+ gem.description = "Coming soon"
22
+ gem.email = "jonerikdsuero@gmail.com"
23
+ gem.authors = ["Jon Erik Suero", "Elan Dubrofsky"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rake/testtask'
29
+ Rake::TestTask.new(:test) do |test|
30
+ test.libs << 'lib' << 'test'
31
+ test.pattern = 'test/**/test_*.rb'
32
+ test.verbose = true
33
+ end
34
+
35
+ task :default => :test
36
+
37
+ require 'rdoc/task'
38
+ Rake::RDocTask.new do |rdoc|
39
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
40
+
41
+ rdoc.rdoc_dir = 'rdoc'
42
+ rdoc.title = "activitylog #{version}"
43
+ rdoc.rdoc_files.include('README*')
44
+ rdoc.rdoc_files.include('lib/**/*.rb')
45
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.0
@@ -0,0 +1,27 @@
1
+ class ActivityLog < ActiveRecord::Base
2
+
3
+ serialize :data, Hash
4
+
5
+ belongs_to :parent, :class_name => 'ActivityLog', :foreign_key => 'parent_activity_id'
6
+ has_many :children, :class_name => 'ActivityLog', :foreign_key => 'parent_activity_id'
7
+
8
+ def self.create_new(user, action, object, data={}, parent_activity_id=nil)
9
+
10
+ options = {
11
+ "user_id" => user.id,
12
+ "object_id" => object.id,
13
+ "object_type" => object.class.name,
14
+ "action" => action,
15
+ "data" => data,
16
+ "parent_activity_id" => parent_activity_id
17
+ }
18
+ log = ActivityLog.create(options)
19
+
20
+ if log.save
21
+ log
22
+ else
23
+ raise "ActivityLog failed to be saved" # TODO: this is just temporary
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1,41 @@
1
+ module ActivityLogger
2
+
3
+ extend ActiveSupport::Concern
4
+
5
+ mattr_accessor :stored_parent_activity_id
6
+
7
+ # INSTANCE METHODS
8
+ def destroy_parent_activity_id
9
+ self.stored_parent_activity_id = nil
10
+ end
11
+
12
+ def record_model_activity_log(action_to_store)
13
+ # if current_user_id == nil, then the User is in the process of Logging In
14
+ current_id = defined?(current_user_id) ? (current_user_id || id) : id
15
+ ActivityLog.create_new(User.find(current_id), action_to_store, self, changes, self.stored_parent_activity_id)
16
+ end
17
+
18
+ def record_controller_activity_log
19
+ return unless params[:id].present?
20
+ return if request.get? #exit if it's a get
21
+ object = controller_name.classify.constantize.find_by_id(params[:id]) #TODO: mk-- change find for LoanStep if searching by step name and loan_id
22
+ return unless object.present?
23
+ activity = ActivityLog.create_new(User.find(current_user.try(:id) || id), params[:controller]+"/"+params[:action], object, params)
24
+ self.stored_parent_activity_id = activity.id
25
+ end
26
+
27
+ # CLASS METHODS (self.)
28
+ module ClassMethods
29
+ def log_model_activity
30
+ self.has_many :object_activity_logs, :foreign_key => 'object_id', :class_name => 'ActivityLog', :conditions => {:object_type => self.class.name}
31
+ self.after_create {record_model_activity_log("create")}
32
+ self.after_update {record_model_activity_log("update")}
33
+ self.before_destroy {record_model_activity_log("destroy")}
34
+ end
35
+
36
+ def log_controller_activity
37
+ self.before_filter {record_controller_activity_log}
38
+ self.after_filter {destroy_parent_activity_id}
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,3 @@
1
+ require 'activity_log/activity_log'
2
+ require 'activity_log/activity_logger.rb'
3
+ ActiveRecord::Base.send(:include, ActivityLogger)
@@ -0,0 +1,26 @@
1
+ # Requires
2
+ require 'rails/generators'
3
+ require 'rails/generators/migration'
4
+
5
+ class ActivityLogGenerator < Rails::Generators::Base
6
+ include Rails::Generators::Migration
7
+ def self.source_root
8
+ @source_root ||= File.join(File.dirname(__FILE__), 'templates')
9
+ end
10
+
11
+ def self.next_migration_number(dirname)
12
+ if ActiveRecord::Base.timestamped_migrations
13
+ Time.new.utc.strftime("%Y%m%d%H%M%S")
14
+ else
15
+ "%.3d" % (current_migration_number(dirname) + 1)
16
+ end
17
+ end
18
+
19
+ def create_migration_file
20
+ migration_template 'create_activity_logs.rb', 'db/migrate/create_activity_logs.rb'
21
+ end
22
+
23
+ def create_initializer_file
24
+ create_file "config/initializers/activity_log.rb", "require 'activity_log'"
25
+ end
26
+ end
@@ -0,0 +1,13 @@
1
+ class CreateActivityLogs < ActiveRecord::Migration
2
+ def change
3
+ create_table :activity_logs do |t|
4
+ t.integer :user_id
5
+ t.integer :object_id
6
+ t.string :object_type
7
+ t.string :action
8
+ t.integer :parent_activity_id
9
+ t.binary :data, :limit => 10.megabyte
10
+ t.timestamps
11
+ end
12
+ end
13
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'activitylog'
16
+
17
+ class Test::Unit::TestCase
18
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestActivityLog < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: activitylog
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Jon Erik Suero
8
+ - Elan Dubrofsky
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-10-15 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: shoulda
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ! '>='
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ! '>='
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: bundler
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ~>
33
+ - !ruby/object:Gem::Version
34
+ version: '1.0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ~>
40
+ - !ruby/object:Gem::Version
41
+ version: '1.0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: jeweler
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ~>
47
+ - !ruby/object:Gem::Version
48
+ version: 1.8.7
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ~>
54
+ - !ruby/object:Gem::Version
55
+ version: 1.8.7
56
+ description: Coming soon
57
+ email: jonerikdsuero@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files:
61
+ - LICENSE.txt
62
+ - README.markdown
63
+ files:
64
+ - .document
65
+ - Gemfile
66
+ - Gemfile.lock
67
+ - LICENSE.txt
68
+ - README.markdown
69
+ - Rakefile
70
+ - VERSION
71
+ - lib/activity_log.rb
72
+ - lib/activity_log/activity_log.rb
73
+ - lib/activity_log/activity_logger.rb
74
+ - lib/generators/activity_log/activity_log_generator.rb
75
+ - lib/generators/activity_log/templates/create_activity_logs.rb
76
+ - test/helper.rb
77
+ - test/test_activity_log.rb
78
+ homepage: http://github.com/JonErikDSuero/activitylog
79
+ licenses:
80
+ - MIT
81
+ metadata: {}
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ! '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ! '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubyforge_project:
98
+ rubygems_version: 2.0.5
99
+ signing_key:
100
+ specification_version: 4
101
+ summary: Provides Activity Log functionality to your code
102
+ test_files: []