activesupport-current_attributes 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ef3e1d0c25a11980d9e3fc182fb3217c97ebbef1
|
4
|
+
data.tar.gz: d762fb817f5cdf6e1292f7c80995cea31ff477b9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b076dd6d58833383aa7a18facf2cad15e0e257742aa7924290def714db94094b117230d32493408e37113dbe67274d9b8893028a4ec4551081fa93a0d4535265
|
7
|
+
data.tar.gz: 4a19daa3cf2beb29f8d625f7bec16065d234222c3133afec39a093c372b024b8d8caea491b556a89181ccf8503f65d9f338b46d3e2bb227ff9906e2e0895d104
|
data/MIT-LICENSE
ADDED
@@ -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.
|
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
|
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.
|
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
|
-
|
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.
|
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.
|
7
|
-
app.executor.
|
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
|
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.
|
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-
|
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
|
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
|
data/LICENSE.txt
DELETED
@@ -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.
|