Skip to content

Commit

Permalink
Reverts release 1.6.0 - no longer use Fiber
Browse files Browse the repository at this point in the history
See #96
  • Loading branch information
professor authored and steveklabnik committed May 1, 2024
1 parent 779d971 commit ded0d62
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 19 deletions.
22 changes: 6 additions & 16 deletions lib/request_store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,28 @@
require "request_store/railtie" if defined?(Rails::Railtie)

module RequestStore
if Fiber.respond_to?(:[])
def self.scope
Fiber
end
else
def self.scope
Thread.current
end
end

def self.store
scope[:request_store] ||= {}
Thread.current[:request_store] ||= {}
end

def self.store=(store)
scope[:request_store] = store
Thread.current[:request_store] = store
end

def self.clear!
scope[:request_store] = {}
Thread.current[:request_store] = {}
end

def self.begin!
scope[:request_store_active] = true
Thread.current[:request_store_active] = true
end

def self.end!
scope[:request_store_active] = false
Thread.current[:request_store_active] = false
end

def self.active?
scope[:request_store_active] || false
Thread.current[:request_store_active] || false
end

def self.read(key)
Expand Down
2 changes: 1 addition & 1 deletion lib/request_store/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module RequestStore
VERSION = "1.6.0"
VERSION = "1.7.0"
end
4 changes: 2 additions & 2 deletions test/request_store_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ def test_delete
assert_equal 4, RequestStore.delete(:foo) { 2 + 2 }
end

def test_delegates_to_scope
def test_delegates_to_thread
RequestStore.store[:foo] = 1
assert_equal 1, RequestStore.scope[:request_store][:foo]
assert_equal 1, Thread.current[:request_store][:foo]
end

def test_active_state
Expand Down

0 comments on commit ded0d62

Please sign in to comment.