activesupport-current_attributes 0.0.1 → 0.0.2

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: 2b109012074bb1ed8a31034fbc47b79f844333fa
4
- data.tar.gz: 45e6b01cb1e3fce6daff93a13b008f1eb5527a30
3
+ metadata.gz: ef3e1d0c25a11980d9e3fc182fb3217c97ebbef1
4
+ data.tar.gz: d762fb817f5cdf6e1292f7c80995cea31ff477b9
5
5
  SHA512:
6
- metadata.gz: 98b5474e715b5f0bf4fa3947774b4db41766fa0e4affec54391b9f8e91e5ff85e86e760e3355f86e91e4526f3d1c8f5819f4a1ea60f6e8b0982fdf8b81e7783c
7
- data.tar.gz: 6d0549c0849fee4100ee5267cdf8474181c046636bddcb09c24e11371531ccc3152ea545da5b9f37df14a3564f37c78608dd8775de0d87655337b6a738862418
6
+ metadata.gz: b076dd6d58833383aa7a18facf2cad15e0e257742aa7924290def714db94094b117230d32493408e37113dbe67274d9b8893028a4ec4551081fa93a0d4535265
7
+ data.tar.gz: 4a19daa3cf2beb29f8d625f7bec16065d234222c3133afec39a093c372b024b8d8caea491b556a89181ccf8503f65d9f338b46d3e2bb227ff9906e2e0895d104
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2005-2017 David Heinemeier Hansson
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.md CHANGED
@@ -51,7 +51,7 @@ The following full app-like example demonstrates how to use a `Current` class to
51
51
 
52
52
  private
53
53
  def authenticate
54
- if authenticated_user = User.find(cookies.signed[:user_id])
54
+ if authenticated_user = User.find_by(id: cookies.signed[:user_id])
55
55
  Current.user = authenticated_user
56
56
  else
57
57
  redirect_to new_session_url
@@ -1,6 +1,6 @@
1
1
  module ActiveSupport
2
2
  # Abstract super class that provides a thread-isolated attributes singleton, which resets automatically
3
- # before and after reach request. This allows you to keep all the per-request attributes easily
3
+ # before and after each request. This allows you to keep all the per-request attributes easily
4
4
  # available to the whole system.
5
5
  #
6
6
  # The following full app-like example demonstrates how to use a Current class to
@@ -31,7 +31,7 @@ module ActiveSupport
31
31
  #
32
32
  # private
33
33
  # def authenticate
34
- # if authenticated_user = User.find(cookies.signed[:user_id])
34
+ # if authenticated_user = User.find_by(id: cookies.signed[:user_id])
35
35
  # Current.user = authenticated_user
36
36
  # else
37
37
  # redirect_to new_session_url
@@ -87,9 +87,7 @@ module ActiveSupport
87
87
  class << self
88
88
  # Returns singleton instance for this class in this thread. If none exists, one is created.
89
89
  def instance
90
- Thread.current[:"current_attributes_for_#{name}"] ||= new.tap do |instance|
91
- current_instances << instance
92
- end
90
+ current_instances[name] ||= new
93
91
  end
94
92
 
95
93
  # Declares one or more attributes that will be given both class and instance accessor methods.
@@ -125,7 +123,12 @@ module ActiveSupport
125
123
  delegate :set, :reset, to: :instance
126
124
 
127
125
  def reset_all # :nodoc:
128
- current_instances.each(&:reset)
126
+ current_instances.each_value(&:reset)
127
+ end
128
+
129
+ def clear_all # :nodoc:
130
+ reset_all
131
+ current_instances.clear
129
132
  end
130
133
 
131
134
  private
@@ -134,7 +137,7 @@ module ActiveSupport
134
137
  end
135
138
 
136
139
  def current_instances
137
- Thread.current[:current_attributes_instances] ||= []
140
+ Thread.current[:current_attributes_instances] ||= {}
138
141
  end
139
142
 
140
143
  def method_missing(name, *args, &block)
@@ -3,8 +3,9 @@ require 'active_support'
3
3
  module ActiveSupport
4
4
  class Railtie < Rails::Railtie # :nodoc:
5
5
  initializer "active_support.reset_all_current_attributes_instances", before: "active_support.deprecation_behavior" do |app|
6
- app.executor.to_run { ActiveSupport::CurrentAttributes.reset_all }
7
- app.executor.to_complete { ActiveSupport::CurrentAttributes.reset_all }
6
+ app.reloader.before_class_unload { ActiveSupport::CurrentAttributes.clear_all }
7
+ app.executor.to_run { ActiveSupport::CurrentAttributes.reset_all }
8
+ app.executor.to_complete { ActiveSupport::CurrentAttributes.reset_all }
8
9
  end
9
10
  end
10
11
  end
@@ -1,3 +1,3 @@
1
1
  module CurrentAttributes
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activesupport-current_attributes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Coup Mobility GmbH
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-06 00:00:00.000000000 Z
11
+ date: 2017-07-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -102,7 +102,7 @@ executables: []
102
102
  extensions: []
103
103
  extra_rdoc_files: []
104
104
  files:
105
- - LICENSE.txt
105
+ - MIT-LICENSE
106
106
  - README.md
107
107
  - lib/active_support/current_attributes.rb
108
108
  - lib/active_support/current_attributes/current_attributes.rb
@@ -1,21 +0,0 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2017 Ahmed Hazem
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.