public_activity 0.1.1 → 0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -3,6 +3,11 @@
3
3
  public_activity provides smooth acitivity tracking for your ActiveRecord models in Rails 3.
4
4
  Simply put: it records what has been changed or edited and gives you the ability to present those recorded activities to users - in a similar way Github does it.
5
5
 
6
+ ## Example
7
+
8
+ A picture is worth a thousand words, so here is a visual representation of what this gem is about:
9
+
10
+ ![Example usage](http://i.imgur.com/uGPSm.png)
6
11
 
7
12
  ## Installation
8
13
 
@@ -21,7 +26,7 @@ Add 'tracked' to the model you want to keep track of:
21
26
  class Article < ActiveRecord::Base
22
27
  tracked
23
28
  end
24
- And now, by default create/update activites are recorded in activities table.
29
+ And now, by default create/update/destroy activities are recorded in activities table.
25
30
  To display them you can do a simple query:
26
31
  # some_controller.rb
27
32
  def index
@@ -37,8 +42,12 @@ The only thing left is to add translations to your locale files, for example:
37
42
  article:
38
43
  create: 'Article has been created'
39
44
  update: 'Someone has edited the article'
45
+ destroy: 'Some user removed an article!'
40
46
 
41
47
  This is only a basic example, refer to documentation for more options and customization!
48
+ ## Documentation
49
+
50
+ You can find documentation [here](http://rubydoc.info/gems/public_activity/)
42
51
 
43
52
  ## License
44
53
  Copyright (c) 2011 Piotrek Okoński, released under the MIT license
@@ -1,4 +1,4 @@
1
- require 'rails'
1
+ require 'active_support/concern'
2
2
  require 'active_support/dependencies'
3
3
  require 'active_record'
4
4
  # +public_activity+ keeps track of changes made to models
@@ -30,6 +30,7 @@ require 'active_record'
30
30
  # activity:
31
31
  # create: 'New article has been created'
32
32
  # update: 'Someone modified the article'
33
+ # destroy: 'Someone deleted the article!'
33
34
  #
34
35
  # Check {PublicActivity::ClassMethods#tracked} for more details about customizing and specifing
35
36
  # ownership to users.
@@ -39,6 +40,7 @@ module PublicActivity
39
40
  autoload :Activity
40
41
  autoload :Tracked
41
42
  autoload :Creation
43
+ autoload :Destruction
42
44
  autoload :VERSION
43
45
  autoload :Common
44
46
 
@@ -80,19 +82,17 @@ module PublicActivity
80
82
  # documentation.
81
83
  def tracked(options = {})
82
84
  return if tracked?
83
- include Creation
84
85
  include Common
85
-
86
+ include Creation
87
+ include Destruction
88
+
86
89
  if options[:owner]
87
90
  self.activity_owner_global = options[:owner]
88
91
  end
89
92
  if options[:params]
90
93
  self.activity_params_global = options[:params]
91
94
  end
92
- has_many :activities, :class_name => "PublicActivity::Activity", :as => :trackable
93
-
94
-
95
-
95
+ has_many :activities, :class_name => "PublicActivity::Activity", :as => :trackable
96
96
  end
97
97
  end
98
98
 
@@ -24,6 +24,8 @@ module PublicActivity
24
24
  # article:
25
25
  # create: "Someone has created an article '%{title}'"
26
26
  # update: "Article '%{title}' has been modified"
27
+ # destroy: "Someone deleted article '%{title}'!"
28
+ #
27
29
  # And in controller:
28
30
  #
29
31
  # def create
@@ -3,27 +3,31 @@ module PublicActivity
3
3
  extend ActiveSupport::Concern
4
4
 
5
5
  module InstanceMethods
6
- # Prepare settings used during creation of Activity record.
7
- # params passed directly to tracked model have priority over
8
- # settings specified in tracked() method
9
- def prepare_settings
10
- # user responsible for the activity
11
- if self.activity_owner
12
- owner = self.activity_owner
13
- else
14
- case self.activity_owner_global
15
- when Symbol, String
16
- owner = self[self.class.activity_owner_global]
17
- when Proc
18
- owner = self.class.activity_owner_global.call
19
- end
6
+ private
7
+ # Creates activity based on supplied arguments
8
+ def create_activity(key, owner, params)
9
+ self.activities.create(:key => key, :owner => owner, :parameters => params)
20
10
  end
21
- #customizable parameters
22
- parameters = self.class.activity_params_global
23
- parameters.merge! self.activity_params if self.activity_params
24
- return {:owner => owner, :parameters => parameters}
25
- end
26
-
11
+ # Prepare settings used during creation of Activity record.
12
+ # params passed directly to tracked model have priority over
13
+ # settings specified in tracked() method
14
+ def prepare_settings
15
+ # user responsible for the activity
16
+ if self.activity_owner
17
+ owner = self.activity_owner
18
+ else
19
+ case self.activity_owner_global
20
+ when Symbol, String
21
+ owner = self[self.class.activity_owner_global]
22
+ when Proc
23
+ owner = self.class.activity_owner_global.call
24
+ end
25
+ end
26
+ #customizable parameters
27
+ parameters = self.class.activity_params_global
28
+ parameters.merge! self.activity_params if self.activity_params
29
+ return {:owner => owner, :parameters => parameters}
30
+ end
27
31
  end
28
32
  end
29
33
  end
@@ -8,12 +8,7 @@ module PublicActivity
8
8
  end
9
9
 
10
10
  module InstanceMethods
11
- private
12
- # Creates activity based on supplied arguments
13
- def create_activity(key, owner, params)
14
- self.activities.create(:key => key, :owner => owner, :parameters => params)
15
- end
16
-
11
+ private
17
12
  # Creates activity upon creation of the tracked model
18
13
  def activity_on_create
19
14
  settings = prepare_settings
@@ -0,0 +1,18 @@
1
+ module PublicActivity
2
+ module Destruction
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ before_destroy :activity_on_destroy
7
+ end
8
+
9
+ module InstanceMethods
10
+ private
11
+ # Records an activity upon destruction of the tracked model
12
+ def activity_on_destroy
13
+ settings = prepare_settings
14
+ create_activity("activity."+self.class.name.downcase+".destroy", settings[:owner], settings[:parameters])
15
+ end
16
+ end
17
+ end
18
+ end
@@ -1,3 +1,3 @@
1
1
  module PublicActivity
2
- VERSION = '0.1.1'
2
+ VERSION = '0.2'
3
3
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: public_activity
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.1
5
+ version: "0.2"
6
6
  platform: ruby
7
7
  authors:
8
8
  - "Piotrek Oko\xC5\x84ski"
@@ -11,7 +11,7 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2011-03-07 00:00:00 +01:00
14
+ date: 2011-03-10 00:00:00 +01:00
15
15
  default_executable:
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
@@ -74,10 +74,10 @@ files:
74
74
  - lib/public_activity/activity.rb
75
75
  - lib/public_activity/common.rb
76
76
  - lib/public_activity/creation.rb
77
+ - lib/public_activity/destruction.rb
77
78
  - lib/public_activity/tracked.rb
78
79
  - lib/public_activity/version.rb
79
80
  - Gemfile
80
- - Gemfile.lock
81
81
  - Rakefile
82
82
  - README.md
83
83
  - MIT-LICENSE
@@ -1,85 +0,0 @@
1
- GEM
2
- remote: http://rubygems.org/
3
- specs:
4
- abstract (1.0.0)
5
- actionmailer (3.0.5)
6
- actionpack (= 3.0.5)
7
- mail (~> 2.2.15)
8
- actionpack (3.0.5)
9
- activemodel (= 3.0.5)
10
- activesupport (= 3.0.5)
11
- builder (~> 2.1.2)
12
- erubis (~> 2.6.6)
13
- i18n (~> 0.4)
14
- rack (~> 1.2.1)
15
- rack-mount (~> 0.6.13)
16
- rack-test (~> 0.5.7)
17
- tzinfo (~> 0.3.23)
18
- activemodel (3.0.5)
19
- activesupport (= 3.0.5)
20
- builder (~> 2.1.2)
21
- i18n (~> 0.4)
22
- activerecord (3.0.5)
23
- activemodel (= 3.0.5)
24
- activesupport (= 3.0.5)
25
- arel (~> 2.0.2)
26
- tzinfo (~> 0.3.23)
27
- activeresource (3.0.5)
28
- activemodel (= 3.0.5)
29
- activesupport (= 3.0.5)
30
- activesupport (3.0.5)
31
- arel (2.0.9)
32
- builder (2.1.2)
33
- diff-lcs (1.1.2)
34
- erubis (2.6.6)
35
- abstract (>= 1.0.0)
36
- i18n (0.5.0)
37
- mail (2.2.15)
38
- activesupport (>= 2.3.6)
39
- i18n (>= 0.4.0)
40
- mime-types (~> 1.16)
41
- treetop (~> 1.4.8)
42
- mime-types (1.16)
43
- mocha (0.9.12)
44
- polyglot (0.3.1)
45
- rack (1.2.1)
46
- rack-mount (0.6.13)
47
- rack (>= 1.0.0)
48
- rack-test (0.5.7)
49
- rack (>= 1.0)
50
- rails (3.0.5)
51
- actionmailer (= 3.0.5)
52
- actionpack (= 3.0.5)
53
- activerecord (= 3.0.5)
54
- activeresource (= 3.0.5)
55
- activesupport (= 3.0.5)
56
- bundler (~> 1.0)
57
- railties (= 3.0.5)
58
- railties (3.0.5)
59
- actionpack (= 3.0.5)
60
- activesupport (= 3.0.5)
61
- rake (>= 0.8.7)
62
- thor (~> 0.14.4)
63
- rake (0.8.7)
64
- rspec (2.5.0)
65
- rspec-core (~> 2.5.0)
66
- rspec-expectations (~> 2.5.0)
67
- rspec-mocks (~> 2.5.0)
68
- rspec-core (2.5.1)
69
- rspec-expectations (2.5.0)
70
- diff-lcs (~> 1.1.2)
71
- rspec-mocks (2.5.0)
72
- thor (0.14.6)
73
- treetop (1.4.9)
74
- polyglot (>= 0.3.1)
75
- tzinfo (0.3.24)
76
- yard (0.6.4)
77
-
78
- PLATFORMS
79
- ruby
80
-
81
- DEPENDENCIES
82
- mocha
83
- rails
84
- rspec
85
- yard