thread-inheritable_attributes 1.0.0 → 1.1.0.beta1

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: 88d5993842aa363e7be7ff1106bc3002eacb4e6f
4
- data.tar.gz: 92e4325b4a5a9b1f33cba9f1183db2d2baba4103
3
+ metadata.gz: 83c5bf46acdb7eece51054d9dbb2d2c8ba5a7cd3
4
+ data.tar.gz: e1a1e6199bd7630e7ef75d2c35d005e8e0049366
5
5
  SHA512:
6
- metadata.gz: 13df0749c60e8ec6de808f7259eae4318a616603a8af1012ca766253e689cf7fe28b2972f72ed8cf127acb4123be9c867b5b4601154b0007d352256e8a6a4f81
7
- data.tar.gz: 6d39855d5cdf1bcf645d6397a9f67e367256d6200cbd59afd7073217c8179f8a01c21b800b62de64377fd0f1d9fa7a0ca57768786391c29b218d28c33d0c4c62
6
+ metadata.gz: bfbd56fa3ae6f6ee3033cf2805a2a53f4d998bc208513e8d800da99a4de267e991dea72c70977e152e047f569b87963be85c00efaee180eaa2c4f271f563a239
7
+ data.tar.gz: dbabee7900d20b1386106ecb4c62c351acae02dd60043a0d67ea042d21a2b302ae08df5c10d32e425c2a1c4d7eed6827759c42b1ad7f212778221a6d2457d9b6
data/CHANGELOG.md CHANGED
@@ -1,9 +1,19 @@
1
- ## Current Release v1.0.0
1
+ ## v1.1.0.beta1 - 2016-06-14
2
+
3
+ ### Fix
4
+ Add request_store gem as an optional dependency for when working within the context of a multi-threaded web server.
5
+ Addresses the use of `Thread.current` and replaces it with `RequestStore` when the gem can be required.
6
+
7
+ > if you use Thread.current, and you use [a multi-threaded web server] ..., watch out! Values can stick around longer than you'd expect, and this can cause bugs."
8
+
9
+ > -- <cite>[request_store docs](https://github.com/steveklabnik/request_store#the-problem)</cite>
10
+
11
+ ## v1.0.0 - 2016-05-25
2
12
 
3
13
  No changes from v0.2.0, but it is being promoted to production ready.
4
14
  It's been used on multiple production environments for 3 months without issues.
5
15
 
6
- ## Current Release v0.2.0
16
+ ## v0.2.0 - 2016-03-14
7
17
 
8
18
  ### Fix
9
19
  - Addressing issue of args not being passed to thread block when creating a Thread and passing args to the initializer.
data/README.md CHANGED
@@ -10,6 +10,14 @@ Add this line to your application's Gemfile:
10
10
  gem "thread-inheritable_attributes"
11
11
  ```
12
12
 
13
+ [request_store](https://github.com/steveklabnik/request_store) is an optional dependency for when working within the context of a multi-threaded web server.
14
+
15
+ If using Rails no config is required, except including the gem. When using other Rack based frameworks see [docs](https://github.com/steveklabnik/request_store#no-rails-no-problem) for including middleware.
16
+
17
+ ```ruby
18
+ gem "request_store"
19
+ ```
20
+
13
21
  And then execute:
14
22
 
15
23
  $ bundle
@@ -41,7 +49,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
41
49
 
42
50
  ## Contributing
43
51
 
44
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/thread_variable_cascade. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
52
+ Bug reports and pull requests are welcome on GitHub at https://github.com/zeisler/thread_variable_cascade. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
45
53
 
46
54
 
47
55
  ## License
@@ -1,13 +1,14 @@
1
1
  require "thread"
2
+ require "thread/inheritable_attributes/request_store"
2
3
 
3
4
  class Thread
4
5
  INHERITABLE_ATTRIBUTES_MUTEX = Mutex.new
5
6
  alias_method :_initialize, :initialize
6
7
 
7
8
  def initialize(*args, &block)
8
- inheritable_attributes = Thread.current.inheritable_attributes
9
+ _inheritable_attributes = inheritable_attributes
9
10
  _initialize(*args) do |*block_args|
10
- Thread.current[:inheritable_attributes] = inheritable_attributes
11
+ RequestStore[:inheritable_attributes] = _inheritable_attributes
11
12
  block.call(block_args)
12
13
  end
13
14
  end
@@ -27,7 +28,6 @@ class Thread
27
28
  protected
28
29
 
29
30
  def inheritable_attributes
30
- self[:inheritable_attributes] ||= {}
31
+ RequestStore[:inheritable_attributes] ||= {}
31
32
  end
32
-
33
33
  end
@@ -0,0 +1,13 @@
1
+ module CanBeLoaded
2
+ def self.call(file)
3
+ loaded = false
4
+ begin
5
+ require file
6
+ loaded = true
7
+ rescue LoadError => e
8
+ raise e unless /^cannot load such file -- #{file}$/ =~ e.message
9
+ false
10
+ end
11
+ loaded
12
+ end
13
+ end
@@ -0,0 +1,14 @@
1
+ require "thread/inheritable_attributes/can_be_loaded"
2
+
3
+ class Thread
4
+ if CanBeLoaded.call("request_store") && defined? ::RequestStore
5
+ request_store_version = Gem::Version.new(::RequestStore::VERSION)
6
+ if request_store_version >= Gem::Version.new("1.0") && request_store_version < Gem::Version.new("2.0")
7
+ RequestStore = ::RequestStore
8
+ else
9
+ raise "RequestStore version: #{::RequestStore::Version} unsupported"
10
+ end
11
+ else
12
+ RequestStore = Thread.current
13
+ end
14
+ end
@@ -1,5 +1,5 @@
1
1
  class Thread
2
2
  module InheritableAttributes
3
- VERSION = "1.0.0"
3
+ VERSION = "1.1.0.beta1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thread-inheritable_attributes
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0.beta1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dustin Zeisler
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-05-25 00:00:00.000000000 Z
11
+ date: 2016-06-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -72,6 +72,8 @@ files:
72
72
  - bin/console
73
73
  - bin/setup
74
74
  - lib/thread/inheritable_attributes.rb
75
+ - lib/thread/inheritable_attributes/can_be_loaded.rb
76
+ - lib/thread/inheritable_attributes/request_store.rb
75
77
  - lib/thread/inheritable_attributes/version.rb
76
78
  - thread-inheritable_attributes.gemspec
77
79
  homepage: https://github.com/zeisler/thread-inheritable_attributes
@@ -89,9 +91,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
89
91
  version: '0'
90
92
  required_rubygems_version: !ruby/object:Gem::Requirement
91
93
  requirements:
92
- - - ">="
94
+ - - ">"
93
95
  - !ruby/object:Gem::Version
94
- version: '0'
96
+ version: 1.3.1
95
97
  requirements: []
96
98
  rubyforge_project:
97
99
  rubygems_version: 2.2.5