public_activity 0.3 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -19,24 +19,32 @@ or in your Gemfile:
19
19
  ## Usage
20
20
 
21
21
  Create migration for activities (in your Rails project):
22
+
22
23
  rails g public_activity:migration
23
24
  rake db:migrate
24
25
 
25
26
  Add 'tracked' to the model you want to keep track of:
27
+
26
28
  class Article < ActiveRecord::Base
27
29
  tracked
28
30
  end
31
+
29
32
  And now, by default create/update/destroy activities are recorded in activities table.
30
33
  To display them you can do a simple query:
34
+
31
35
  # some_controller.rb
32
36
  def index
33
37
  @activities = PublicActivity::Activity.all
34
38
  end
39
+
35
40
  And in your views:
41
+
36
42
  <% for activity in @activities %>
37
43
  <%= activity.text %><br/>
38
44
  <% end %>
45
+
39
46
  The only thing left is to add translations to your locale files, for example:
47
+
40
48
  en:
41
49
  activity:
42
50
  article:
@@ -4,11 +4,26 @@ module PublicActivity
4
4
  extend ActiveSupport::Concern
5
5
  # Instance methods used by other methods in PublicActivity module.
6
6
  module InstanceMethods
7
+ # Directly creates activity record in the database, based on supplied arguments.
8
+ # Only first argument - key - is required.
9
+ #
10
+ # == Usage:
11
+ #
12
+ # current_user.create_activity("activity.user.avatar_changed") if @user.avatar_file_name_changed?
13
+ #
14
+ # == Parameters:
15
+ # [key]
16
+ # Custom key that will be used as a i18n translation key - *required*
17
+ # [owner]
18
+ # Polymorphic relation specifying the owner of this activity (for example, a User who performed this task) - *optional*
19
+ # [params]
20
+ # Hash with parameters passed directly into i18n.translate method - *optional*
21
+ #
22
+ def create_activity(key, owner = nil, params = {})
23
+ self.activities.create(:key => key, :owner => owner, :parameters => params)
24
+ end
25
+
7
26
  private
8
- # Creates activity based on supplied arguments
9
- def create_activity(key, owner, params)
10
- self.activities.create(:key => key, :owner => owner, :parameters => params)
11
- end
12
27
  # Prepares settings used during creation of Activity record.
13
28
  # params passed directly to tracked model have priority over
14
29
  # settings specified in tracked() method
@@ -57,7 +57,7 @@ module PublicActivity
57
57
  # @article = Article.new
58
58
  # @article.save
59
59
  # @article.activities.last.key #=> "activity.article.create"
60
- # By default, key looks like "activity.[class_name].[create|update|destroy]"
60
+ # By default, key looks like "activity.class_name.create|update|destroy"
61
61
  #
62
62
  # You can customize it, by setting your own key:
63
63
  # @article = Article.new
@@ -87,14 +87,19 @@ module PublicActivity
87
87
  # method. It is later used in {Activity#text} method.
88
88
  # == Example:
89
89
  # @article.activity :parameters => {:title => @article.title, :short => truncate(@article.text, :length => 50)}
90
- # Everything specified here has a lower priority than parameters specified directly in {Tracked#activity} method.
90
+ # Everything specified here has a lower priority than parameters specified directly in {Tracked::InstanceMethods#activity} method.
91
91
  # So treat it as a place where you provide 'default' values.
92
92
  # For more dynamic settings refer to {Activity} model
93
93
  # documentation.
94
+ # [:skip_defaults]
95
+ # Disables recording of activities on create/update/destroy leaving that to programmer's choice. Check {PublicActivity::Common::InstanceMethods#create_activity}
96
+ # for a guide on how to manually record activities.
94
97
  def tracked(options = {})
95
98
  include Common
96
- include Creation
97
- include Destruction
99
+ if !options[:skip_defaults]
100
+ include Creation
101
+ include Destruction
102
+ end
98
103
 
99
104
  if options[:owner]
100
105
  self.activity_owner_global = options[:owner]
@@ -1,4 +1,4 @@
1
1
  module PublicActivity
2
2
  # A constant with gem's version
3
- VERSION = '0.3'
3
+ VERSION = '0.3.1'
4
4
  end
metadata CHANGED
@@ -1,72 +1,70 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: public_activity
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.1
4
5
  prerelease:
5
- version: "0.3"
6
6
  platform: ruby
7
- authors:
8
- - "Piotrek Oko\xC5\x84ski"
9
- - "Kuba Oko\xC5\x84ski"
7
+ authors:
8
+ - Piotrek Okoński
9
+ - Kuba Okoński
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
-
14
- date: 2011-04-10 00:00:00 +02:00
13
+ date: 2011-09-08 00:00:00.000000000 +02:00
15
14
  default_executable:
16
- dependencies:
17
- - !ruby/object:Gem::Dependency
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
18
17
  name: activerecord
19
- prerelease: false
20
- requirement: &id001 !ruby/object:Gem::Requirement
18
+ requirement: &70011400 !ruby/object:Gem::Requirement
21
19
  none: false
22
- requirements:
23
- - - ">="
24
- - !ruby/object:Gem::Version
20
+ requirements:
21
+ - - ! '>='
22
+ - !ruby/object:Gem::Version
25
23
  version: 3.0.0
26
24
  type: :runtime
27
- version_requirements: *id001
28
- - !ruby/object:Gem::Dependency
29
- name: activesupport
30
25
  prerelease: false
31
- requirement: &id002 !ruby/object:Gem::Requirement
26
+ version_requirements: *70011400
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: &70011140 !ruby/object:Gem::Requirement
32
30
  none: false
33
- requirements:
34
- - - ">="
35
- - !ruby/object:Gem::Version
31
+ requirements:
32
+ - - ! '>='
33
+ - !ruby/object:Gem::Version
36
34
  version: 3.0.0
37
35
  type: :runtime
38
- version_requirements: *id002
39
- - !ruby/object:Gem::Dependency
40
- name: i18n
41
36
  prerelease: false
42
- requirement: &id003 !ruby/object:Gem::Requirement
37
+ version_requirements: *70011140
38
+ - !ruby/object:Gem::Dependency
39
+ name: i18n
40
+ requirement: &70010890 !ruby/object:Gem::Requirement
43
41
  none: false
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
47
45
  version: 0.5.0
48
46
  type: :runtime
49
- version_requirements: *id003
50
- - !ruby/object:Gem::Dependency
51
- name: rspec
52
47
  prerelease: false
53
- requirement: &id004 !ruby/object:Gem::Requirement
48
+ version_requirements: *70010890
49
+ - !ruby/object:Gem::Dependency
50
+ name: rspec
51
+ requirement: &70010690 !ruby/object:Gem::Requirement
54
52
  none: false
55
- requirements:
56
- - - ">="
57
- - !ruby/object:Gem::Version
58
- version: "0"
53
+ requirements:
54
+ - - ! '>='
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
59
57
  type: :development
60
- version_requirements: *id004
61
- description: Smooth activity tracking for your ActiveRecord models. Provides Activity model with details about actions performed by your users, like adding comments, responding etc.
58
+ prerelease: false
59
+ version_requirements: *70010690
60
+ description: Smooth activity tracking for your ActiveRecord models. Provides Activity
61
+ model with details about actions performed by your users, like adding comments,
62
+ responding etc.
62
63
  email: piotrek@okonski.org
63
64
  executables: []
64
-
65
65
  extensions: []
66
-
67
66
  extra_rdoc_files: []
68
-
69
- files:
67
+ files:
70
68
  - lib/generators/public_activity.rb
71
69
  - lib/generators/public_activity/migration/migration_generator.rb
72
70
  - lib/generators/public_activity/migration/templates/migration.rb
@@ -87,31 +85,28 @@ files:
87
85
  has_rdoc: true
88
86
  homepage: https://github.com/okonski/public_activity
89
87
  licenses: []
90
-
91
88
  post_install_message:
92
89
  rdoc_options: []
93
-
94
- require_paths:
90
+ require_paths:
95
91
  - lib
96
- required_ruby_version: !ruby/object:Gem::Requirement
92
+ required_ruby_version: !ruby/object:Gem::Requirement
97
93
  none: false
98
- requirements:
99
- - - ">="
100
- - !ruby/object:Gem::Version
101
- version: "0"
102
- required_rubygems_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ! '>='
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
99
  none: false
104
- requirements:
105
- - - ">="
106
- - !ruby/object:Gem::Version
107
- version: "0"
100
+ requirements:
101
+ - - ! '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
108
104
  requirements: []
109
-
110
105
  rubyforge_project:
111
- rubygems_version: 1.6.1
106
+ rubygems_version: 1.6.2
112
107
  signing_key:
113
108
  specification_version: 3
114
109
  summary: Smooth activity tracking for ActiveRecord models
115
- test_files:
110
+ test_files:
116
111
  - spec/spec_helper.rb
117
112
  - spec/version_spec.rb