Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
PATH
remote: .
specs:
sentient_user (0.4.0)
sentient_user (0.4.1)
railties (>= 3.1)
request_store (= 1.1)

GEM
remote: https://rubygems.org/
Expand Down Expand Up @@ -39,17 +40,18 @@ GEM
rake (11.1.2)
rdoc (4.2.2)
json (~> 1.4)
request_store (1.1.0)
simplecov (0.11.2)
docile (~> 1.1.0)
json (~> 1.8)
simplecov-html (~> 0.10.0)
simplecov-html (0.10.0)
thor (0.19.1)
thor (0.19.4)
thread_safe (0.3.5)
turn (0.9.7)
ansi
minitest (~> 4)
tzinfo (0.3.48)
tzinfo (0.3.52)

PLATFORMS
ruby
Expand All @@ -64,4 +66,4 @@ DEPENDENCIES
turn

BUNDLED WITH
1.13.1
1.13.5
18 changes: 10 additions & 8 deletions lib/sentient_user.rb
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
require 'request_store'

module SentientUser

def self.included(base)
base.class_eval {
def self.current
Thread.current[:user]
RequestStore.store[:user]
end

def self.current=(o)
raise(ArgumentError,
"Expected an object of class '#{self}', got #{o.inspect}") unless (o.is_a?(self) || o.nil?)
Thread.current[:user] = o
RequestStore.store[:user] = o
end

def make_current
Thread.current[:user] = self
RequestStore.store[:user] = self
end

def current?
!Thread.current[:user].nil? && self.id == Thread.current[:user].id
!RequestStore.store[:user].nil? && self.id == RequestStore.store[:user].id
end

def self.do_as(user, &block)
old_user = self.current

Expand All @@ -44,4 +46,4 @@ def self.included(base)
end
}
end
end
end
4 changes: 2 additions & 2 deletions lib/sentient_user/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module SentientUser
VERSION = "0.4.0"
end
VERSION = "0.4.1"
end
2 changes: 2 additions & 0 deletions sentient_user.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Gem::Specification.new do |gem|
gem.version = SentientUser::VERSION

gem.add_dependency "railties", ">= 3.1"
gem.add_dependency 'request_store', '1.1'

gem.add_development_dependency "rake"
gem.add_development_dependency "rdoc"
gem.add_development_dependency "minitest", "4.7.5"
Expand Down