public_activity 1.4.3 → 1.5.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 133186d2fb5149e6b12c499d588cafb173fa840c
4
- data.tar.gz: 9dfa82ab740c143daa9d3c833bc15d2c7efd4604
3
+ metadata.gz: 111fe89197635000ddcdf89d3d534f9cb00c3443
4
+ data.tar.gz: ab11f3c49c42d58ba8af32a325874c83f5c634db
5
5
  SHA512:
6
- metadata.gz: dada05aea04f8bc8f20e9d474317bffff945d38da725c579feb960498bb7c12990ffd81d58b58448c177a7b20f1ac289b294cd5ef322c499ab9b09e5b8db4532
7
- data.tar.gz: b0d35c25b9f8834fbb6f0fa9f6b3cde6936e3fdeba387b8c3eb2c595fc0ae886dce19e786a862588f2f3008117f75c0044dbdef17055b9d9dc088f12f2e5c043
6
+ metadata.gz: 41d3b14a7bd58a3c321b52f6fb423b5f612e4f5a8c2881a03dbed893bd352ad0a596ad9e4f64d6cb49289d08fa8c780554dde54dc79b20962dd8e59ef10cad58
7
+ data.tar.gz: df0ba2f1a81173d47c9b750696e7e8eab2af04b0eb8483ceefb1c6c86ebd5e79f811672bba60c4caac8b436f60b2500d1346613c5a7c53c35a31467a17186750
@@ -1,23 +1,13 @@
1
1
  module PublicActivity
2
- # @private
3
- @@controllers = Hash.new
4
- # Lambda called after the thread is destroyed.
5
- Finalizer = lambda { |id|
6
- @@controllers.delete id
7
- }
8
-
9
2
  class << self
10
3
  # Setter for remembering controller instance
11
4
  def set_controller(controller)
12
- unless @@controllers.has_key?(Thread.current.object_id)
13
- ObjectSpace.define_finalizer Thread.current, Finalizer
14
- end if RUBY_VERSION != "1.9.3"
15
- @@controllers[Thread.current.object_id] = controller
5
+ Thread.current[:public_activity_controller] = controller
16
6
  end
17
7
 
18
8
  # Getter for accessing the controller instance
19
9
  def get_controller
20
- @@controllers[Thread.current.object_id]
10
+ Thread.current[:public_activity_controller]
21
11
  end
22
12
  end
23
13
 
@@ -26,17 +16,15 @@ module PublicActivity
26
16
  extend ActiveSupport::Concern
27
17
 
28
18
  included do
29
- # use :before_action instead of deprecated before_filter
30
- if respond_to? :before_action
31
- before_action :store_controller_for_public_activity
32
- else
33
- before_filter :store_controller_for_public_activity
34
- end
19
+ around_action :store_controller_for_public_activity if respond_to?(:around_action)
20
+ around_filter :store_controller_for_public_activity unless respond_to?(:around_action)
35
21
  end
36
22
 
37
- # Before filter executed to remember current controller
38
23
  def store_controller_for_public_activity
39
24
  PublicActivity.set_controller(self)
25
+ yield
26
+ ensure
27
+ PublicActivity.set_controller(nil)
40
28
  end
41
29
  end
42
30
  end
@@ -1,4 +1,4 @@
1
1
  module PublicActivity
2
2
  # A constant with gem's version
3
- VERSION = '1.4.3'
3
+ VERSION = '1.5.0'
4
4
  end
@@ -9,33 +9,32 @@ describe PublicActivity::StoreController do
9
9
  it 'stores controller' do
10
10
  controller = StoringController.new
11
11
  PublicActivity.set_controller(controller)
12
- controller.must_be_same_as PublicActivity.instance_eval { class_variable_get(:@@controllers)[Thread.current.object_id] }
12
+ controller.must_be_same_as Thread.current[:public_activity_controller]
13
13
  controller.must_be_same_as PublicActivity.get_controller
14
14
  end
15
15
 
16
16
  it 'stores controller with a filter in controller' do
17
17
  controller = StoringController.new
18
- controller._process_action_callbacks.select {|c| c.kind == :before}.map(&:filter).must_include :store_controller_for_public_activity
19
- controller.instance_eval { store_controller_for_public_activity }
20
- controller.must_be_same_as PublicActivity.class_eval { class_variable_get(:@@controllers)[Thread.current.object_id] }
18
+ controller._process_action_callbacks.select {|c| c.kind == :around}.map(&:filter).must_include :store_controller_for_public_activity
19
+ controller.instance_eval do
20
+ store_controller_for_public_activity do
21
+ controller.must_be_same_as PublicActivity.get_controller
22
+ end
23
+ end
21
24
  end
22
25
 
23
26
  it 'stores controller in a threadsafe way' do
24
- reset_controllers
25
27
  PublicActivity.set_controller(1)
26
28
  PublicActivity.get_controller.must_equal 1
27
29
 
28
30
  a = Thread.new {
29
31
  PublicActivity.set_controller(2)
30
32
  PublicActivity.get_controller.must_equal 2
33
+ PublicActivity.set_controller(nil)
31
34
  }
32
35
 
33
36
  PublicActivity.get_controller.must_equal 1
34
- # cant really test finalizers though
35
- end
36
37
 
37
- private
38
- def reset_controllers
39
- PublicActivity.class_eval { class_variable_set(:@@controllers, {}) }
38
+ PublicActivity.set_controller(nil)
40
39
  end
41
40
  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: 1.4.3
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotrek Okoński
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-02-18 00:00:00.000000000 Z
12
+ date: 2016-03-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: actionpack
@@ -255,7 +255,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
255
255
  version: '0'
256
256
  requirements: []
257
257
  rubyforge_project:
258
- rubygems_version: 2.4.8
258
+ rubygems_version: 2.4.5.1
259
259
  signing_key:
260
260
  specification_version: 4
261
261
  summary: Easy activity tracking for ActiveRecord models
@@ -279,4 +279,3 @@ test_files:
279
279
  - test/views/custom/_test.erb
280
280
  - test/views/layouts/_activity.erb
281
281
  - test/views/public_activity/_test.erb
282
- has_rdoc: