public_activity 0.4.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -7,7 +7,11 @@ Simply put: it records what has been changed or edited and gives you the ability
7
7
 
8
8
  Here is a simple example showing what this gem is about:
9
9
 
10
- ![Example usage](http://i.imgur.com/uGPSm.png)
10
+ ![Example usage](http://i.imgur.com/q0TVx.png)
11
+
12
+ ### Online demo
13
+
14
+ You can see an actual application using this gem here: http://public-activity-example.herokuapp.com/feed
11
15
 
12
16
  ## Upgrading to 0.4
13
17
 
@@ -23,7 +27,9 @@ You can install `public_activity` as you would any other gem:
23
27
 
24
28
  or in your Gemfile:
25
29
 
26
- gem 'public_activity'
30
+ ```ruby
31
+ gem 'public_activity'
32
+ ```
27
33
 
28
34
  ### Database setup
29
35
 
@@ -132,5 +138,10 @@ There are a couple of major differences between 0.3 and 0.4 version. To upgrade,
132
138
 
133
139
  For more customization go [here](http://rubydoc.info/gems/public_activity/index)
134
140
 
141
+ ## Useful examples
142
+
143
+ * [[How to] Set the Activity's owner to current_user by default](https://github.com/pokonski/public_activity/wiki/%5BHow-to%5D-Set-the-Activity's-owner-to-current_user-by-default)
144
+
145
+
135
146
  ## License
136
147
  Copyright (c) 2012 Piotrek Okoński, released under the MIT license
data/UPGRADING CHANGED
@@ -5,4 +5,4 @@
5
5
  public_activity 0.4.0 brings major changes compared to 0.3.X versions,
6
6
  please read https://github.com/pokonski/public_activity#upgrading
7
7
  to learn about all the changes you need to apply to properly
8
- upgrade your applications.
8
+ upgrade your applications.
@@ -12,6 +12,7 @@ module PublicActivity
12
12
  extend ActiveSupport::Autoload
13
13
  autoload :Activist
14
14
  autoload :Activity
15
+ autoload :Config
15
16
  autoload :Tracked
16
17
  autoload :Creation
17
18
  autoload :Update
@@ -19,6 +20,27 @@ module PublicActivity
19
20
  autoload :VERSION
20
21
  autoload :Common
21
22
 
23
+ # Switches PublicActivity on or off.
24
+ # @param value [Boolean]
25
+ # @since 0.5.0
26
+ def self.enabled=(value)
27
+ PublicActivity.config.enabled = value
28
+ end
29
+
30
+ # Returns `true` if PublicActivity is on, `false` otherwise.
31
+ # Enabled by default.
32
+ # @return [Boolean]
33
+ # @since 0.5.0
34
+ def self.enabled?
35
+ !!PublicActivity.config.enabled
36
+ end
37
+
38
+ # Returns PublicActivity's configuration object.
39
+ # @since 0.5.0
40
+ def self.config
41
+ @@config ||= PublicActivity::Config.instance
42
+ end
43
+
22
44
  # Module to be included in ActiveRecord models. Adds required functionality.
23
45
  module Model
24
46
  extend ActiveSupport::Concern
@@ -89,7 +89,7 @@ module PublicActivity
89
89
  # == Variables in templates
90
90
  # From within a template there are two variables at your disposal:
91
91
  # * activity (aliased as *a* for a shortcut)
92
- # * params (aliased as *p*) [converted into a {HashWithIndifferentAccess}]
92
+ # * params (aliased as *p*) [converted into a HashWithIndifferentAccess]
93
93
  #
94
94
  # @example Template for key: _activity.article.create_ (erb)
95
95
  # <p>
@@ -78,6 +78,7 @@ module PublicActivity
78
78
  # @option options [Hash] :params Parameters, see
79
79
  # {PublicActivity.resolve_value}
80
80
  def create_activity(*args)
81
+ return unless self.public_activity_enabled?
81
82
  options = prepare_settings(*args)
82
83
 
83
84
  if call_hook_safe(options[:key].split('.').last)
@@ -0,0 +1,12 @@
1
+ module PublicActivity
2
+ # Class used to initialize configuration object.
3
+ class Config
4
+ include Singleton
5
+ attr_accessor :enabled
6
+
7
+ def initialize
8
+ # Indicates whether PublicActivity is enabled globally
9
+ @enabled = true
10
+ end
11
+ end
12
+ end
@@ -1,6 +1,7 @@
1
1
  module PublicActivity
2
2
  # @private
3
3
  @@controllers = Hash.new
4
+ # Lambda called after the thread is destroyed.
4
5
  Finalizer = lambda { |id|
5
6
  @@controllers.delete id
6
7
  }
@@ -5,11 +5,12 @@ module PublicActivity
5
5
 
6
6
  included do
7
7
  class_attribute :activity_owner_global, :activity_recipient_global,
8
- :activity_params_global, :activity_hooks
9
- self.activity_owner_global = nil
10
- self.activity_recipient_global = nil
11
- self.activity_params_global = {}
12
- self.activity_hooks = {}
8
+ :activity_params_global, :activity_hooks, :public_activity_enabled_for_model
9
+ self.activity_owner_global = nil
10
+ self.activity_recipient_global = nil
11
+ self.activity_params_global = {}
12
+ self.activity_hooks = {}
13
+ self.public_activity_enabled_for_model = true
13
14
  end
14
15
 
15
16
  # @!group Global options
@@ -286,6 +287,25 @@ module PublicActivity
286
287
  nil
287
288
  end
288
289
  end
290
+
291
+ # Switches public_activity off for this class
292
+ def public_activity_off
293
+ self.public_activity_enabled_for_model = false
294
+ end
295
+
296
+ # Switches public_activity on for this class
297
+ def public_activity_on
298
+ self.public_activity_enabled_for_model = true
299
+ end
300
+ end
301
+
302
+ # Returns true if PublicActivity is enabled
303
+ # globally and for this class.
304
+ # @return [Boolean]
305
+ # @api private
306
+ # @since 0.5.0
307
+ def public_activity_enabled?
308
+ PublicActivity.enabled? && self.class.public_activity_enabled_for_model
289
309
  end
290
310
 
291
311
  # Shortcut for {Tracked::ClassMethods#get_hook}
@@ -1,4 +1,4 @@
1
1
  module PublicActivity
2
2
  # A constant with gem's version
3
- VERSION = '0.4.1'
3
+ VERSION = '0.5.0'
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: public_activity
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.5.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-10-15 00:00:00.000000000 Z
13
+ date: 2012-10-23 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord
17
- requirement: !ruby/object:Gem::Requirement
17
+ requirement: &81298800 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,15 +22,10 @@ dependencies:
22
22
  version: 3.0.0
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: !ruby/object:Gem::Requirement
26
- none: false
27
- requirements:
28
- - - ! '>='
29
- - !ruby/object:Gem::Version
30
- version: 3.0.0
25
+ version_requirements: *81298800
31
26
  - !ruby/object:Gem::Dependency
32
27
  name: activesupport
33
- requirement: !ruby/object:Gem::Requirement
28
+ requirement: &81297860 !ruby/object:Gem::Requirement
34
29
  none: false
35
30
  requirements:
36
31
  - - ! '>='
@@ -38,15 +33,10 @@ dependencies:
38
33
  version: 3.0.0
39
34
  type: :runtime
40
35
  prerelease: false
41
- version_requirements: !ruby/object:Gem::Requirement
42
- none: false
43
- requirements:
44
- - - ! '>='
45
- - !ruby/object:Gem::Version
46
- version: 3.0.0
36
+ version_requirements: *81297860
47
37
  - !ruby/object:Gem::Dependency
48
38
  name: actionpack
49
- requirement: !ruby/object:Gem::Requirement
39
+ requirement: &81295830 !ruby/object:Gem::Requirement
50
40
  none: false
51
41
  requirements:
52
42
  - - ! '>='
@@ -54,15 +44,10 @@ dependencies:
54
44
  version: 3.0.0
55
45
  type: :runtime
56
46
  prerelease: false
57
- version_requirements: !ruby/object:Gem::Requirement
58
- none: false
59
- requirements:
60
- - - ! '>='
61
- - !ruby/object:Gem::Version
62
- version: 3.0.0
47
+ version_requirements: *81295830
63
48
  - !ruby/object:Gem::Dependency
64
49
  name: i18n
65
- requirement: !ruby/object:Gem::Requirement
50
+ requirement: &81295360 !ruby/object:Gem::Requirement
66
51
  none: false
67
52
  requirements:
68
53
  - - ! '>='
@@ -70,15 +55,10 @@ dependencies:
70
55
  version: 0.5.0
71
56
  type: :runtime
72
57
  prerelease: false
73
- version_requirements: !ruby/object:Gem::Requirement
74
- none: false
75
- requirements:
76
- - - ! '>='
77
- - !ruby/object:Gem::Version
78
- version: 0.5.0
58
+ version_requirements: *81295360
79
59
  - !ruby/object:Gem::Dependency
80
60
  name: simplecov
81
- requirement: !ruby/object:Gem::Requirement
61
+ requirement: &81128560 !ruby/object:Gem::Requirement
82
62
  none: false
83
63
  requirements:
84
64
  - - ! '>='
@@ -86,15 +66,10 @@ dependencies:
86
66
  version: 0.6.4
87
67
  type: :development
88
68
  prerelease: false
89
- version_requirements: !ruby/object:Gem::Requirement
90
- none: false
91
- requirements:
92
- - - ! '>='
93
- - !ruby/object:Gem::Version
94
- version: 0.6.4
69
+ version_requirements: *81128560
95
70
  - !ruby/object:Gem::Dependency
96
71
  name: bundler
97
- requirement: !ruby/object:Gem::Requirement
72
+ requirement: &81127100 !ruby/object:Gem::Requirement
98
73
  none: false
99
74
  requirements:
100
75
  - - ! '>='
@@ -102,15 +77,10 @@ dependencies:
102
77
  version: '1.1'
103
78
  type: :development
104
79
  prerelease: false
105
- version_requirements: !ruby/object:Gem::Requirement
106
- none: false
107
- requirements:
108
- - - ! '>='
109
- - !ruby/object:Gem::Version
110
- version: '1.1'
80
+ version_requirements: *81127100
111
81
  - !ruby/object:Gem::Dependency
112
82
  name: rake
113
- requirement: !ruby/object:Gem::Requirement
83
+ requirement: &81126290 !ruby/object:Gem::Requirement
114
84
  none: false
115
85
  requirements:
116
86
  - - ! '>='
@@ -118,15 +88,10 @@ dependencies:
118
88
  version: '0.9'
119
89
  type: :development
120
90
  prerelease: false
121
- version_requirements: !ruby/object:Gem::Requirement
122
- none: false
123
- requirements:
124
- - - ! '>='
125
- - !ruby/object:Gem::Version
126
- version: '0.9'
91
+ version_requirements: *81126290
127
92
  - !ruby/object:Gem::Dependency
128
93
  name: sqlite3
129
- requirement: !ruby/object:Gem::Requirement
94
+ requirement: &81125640 !ruby/object:Gem::Requirement
130
95
  none: false
131
96
  requirements:
132
97
  - - ! '>='
@@ -134,15 +99,10 @@ dependencies:
134
99
  version: '0'
135
100
  type: :development
136
101
  prerelease: false
137
- version_requirements: !ruby/object:Gem::Requirement
138
- none: false
139
- requirements:
140
- - - ! '>='
141
- - !ruby/object:Gem::Version
142
- version: '0'
102
+ version_requirements: *81125640
143
103
  - !ruby/object:Gem::Dependency
144
104
  name: mocha
145
- requirement: !ruby/object:Gem::Requirement
105
+ requirement: &81124540 !ruby/object:Gem::Requirement
146
106
  none: false
147
107
  requirements:
148
108
  - - ! '>='
@@ -150,15 +110,10 @@ dependencies:
150
110
  version: 0.12.1
151
111
  type: :development
152
112
  prerelease: false
153
- version_requirements: !ruby/object:Gem::Requirement
154
- none: false
155
- requirements:
156
- - - ! '>='
157
- - !ruby/object:Gem::Version
158
- version: 0.12.1
113
+ version_requirements: *81124540
159
114
  - !ruby/object:Gem::Dependency
160
115
  name: railties
161
- requirement: !ruby/object:Gem::Requirement
116
+ requirement: &81121440 !ruby/object:Gem::Requirement
162
117
  none: false
163
118
  requirements:
164
119
  - - ! '>='
@@ -166,12 +121,7 @@ dependencies:
166
121
  version: 3.0.0
167
122
  type: :development
168
123
  prerelease: false
169
- version_requirements: !ruby/object:Gem::Requirement
170
- none: false
171
- requirements:
172
- - - ! '>='
173
- - !ruby/object:Gem::Version
174
- version: 3.0.0
124
+ version_requirements: *81121440
175
125
  description: Smooth activity tracking for your ActiveRecord models. Provides Activity
176
126
  model with details about actions performed by your users, like adding comments,
177
127
  responding etc.
@@ -191,6 +141,7 @@ files:
191
141
  - lib/public_activity/activist.rb
192
142
  - lib/public_activity/activity.rb
193
143
  - lib/public_activity/common.rb
144
+ - lib/public_activity/config.rb
194
145
  - lib/public_activity/creation.rb
195
146
  - lib/public_activity/destruction.rb
196
147
  - lib/public_activity/store_controller.rb
@@ -208,7 +159,7 @@ licenses: []
208
159
  post_install_message: ! "##################################################\n# NOTE
209
160
  FOR UPGRADING FROM PRE-0.4.0 VERSION #\n##################################################\n\npublic_activity
210
161
  0.4.0 brings major changes compared to 0.3.X versions,\nplease read https://github.com/pokonski/public_activity#upgrading
211
- \nto learn about all the changes you need to apply to properly\nupgrade your applications."
162
+ \nto learn about all the changes you need to apply to properly\nupgrade your applications.\n"
212
163
  rdoc_options: []
213
164
  require_paths:
214
165
  - lib
@@ -226,7 +177,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
226
177
  version: '0'
227
178
  requirements: []
228
179
  rubyforge_project:
229
- rubygems_version: 1.8.24
180
+ rubygems_version: 1.8.17
230
181
  signing_key:
231
182
  specification_version: 3
232
183
  summary: Smooth activity tracking for ActiveRecord models