activerecord-session_store 0.1.2 → 1.0.0.pre

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of activerecord-session_store might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 199a971acd3d868bd22acce4c420c18e9379d15e
4
- data.tar.gz: 72716a9c795e148bbe8f4b52521cd545ab136efc
3
+ metadata.gz: e266cfc34f1078245ab5c7b89003a2fba65041d3
4
+ data.tar.gz: c9f398c65a0511ca359d45c09b824d1af1965142
5
5
  SHA512:
6
- metadata.gz: c0c2e5bc2f6426beae8f3e7954b3c89f91c050ee9f27f15b4144350966b786ea9b8d8580038662155681101e0e37714c169e24b8b57ff582c25147eaf78dd2db
7
- data.tar.gz: 8ccded75455d38d05815730b050fdcd249fb9ef15110c9e7773048e4e064fce653433fa40edbe13d01434947264727decbf3309d37c1ce891815c5cc19307b5a
6
+ metadata.gz: bc865efe6b4efdb8e448b227787bfcc153069796ec22de12e803293f3798124764aee1b3feb50766248399b15795ab12f5775f273677ef4f841521bb2f825e25
7
+ data.tar.gz: 930fa087e6dd906fb2d5df43d3131cbe75808e1008e9280a0e67307f257d800ce0d7885987c6382d423361fa2bfb5aa7840b5062f6860b755bcf29a92ca8f518
@@ -1,4 +1,4 @@
1
- Copyright (c) 2012-2015 David Heinemeier Hansson
1
+ Copyright (c) 2012-2016 David Heinemeier Hansson
2
2
 
3
3
  MIT License
4
4
 
@@ -58,66 +58,83 @@ module ActionDispatch
58
58
  cattr_accessor :session_class
59
59
 
60
60
  SESSION_RECORD_KEY = 'rack.session.record'
61
- ENV_SESSION_OPTIONS_KEY = Rack::Session::Abstract::ENV_SESSION_OPTIONS_KEY
61
+ if Rack.const_defined?(:RACK_SESSION_OPTIONS)
62
+ ENV_SESSION_OPTIONS_KEY = Rack::RACK_SESSION_OPTIONS
63
+ else
64
+ ENV_SESSION_OPTIONS_KEY = Rack::Session::Abstract::ENV_SESSION_OPTIONS_KEY
65
+ end
62
66
 
63
- private
64
- def get_session(env, sid)
65
- logger.silence_logger do
66
- unless sid and session = @@session_class.find_by_session_id(sid)
67
- # If the sid was nil or if there is no pre-existing session under the sid,
68
- # force the generation of a new sid and associate a new session associated with the new sid
69
- sid = generate_sid
70
- session = @@session_class.new(:session_id => sid, :data => {})
71
- end
72
- env[SESSION_RECORD_KEY] = session
73
- [sid, session.data]
67
+ private
68
+ def get_session(request, sid)
69
+ logger.silence_logger do
70
+ unless sid and session = @@session_class.find_by_session_id(sid)
71
+ # If the sid was nil or if there is no pre-existing session under the sid,
72
+ # force the generation of a new sid and associate a new session associated with the new sid
73
+ sid = generate_sid
74
+ session = @@session_class.new(:session_id => sid, :data => {})
74
75
  end
76
+ request.env[SESSION_RECORD_KEY] = session
77
+ [sid, session.data]
75
78
  end
79
+ end
76
80
 
77
- def set_session(env, sid, session_data, options)
78
- logger.silence_logger do
79
- record = get_session_model(env, sid)
80
- record.data = session_data
81
- return false unless record.save
81
+ def write_session(request, sid, session_data, options)
82
+ logger.silence_logger do
83
+ record = get_session_model(request, sid)
84
+ record.data = session_data
85
+ return false unless record.save
82
86
 
83
- session_data = record.data
84
- if session_data && session_data.respond_to?(:each_value)
85
- session_data.each_value do |obj|
86
- obj.clear_association_cache if obj.respond_to?(:clear_association_cache)
87
- end
87
+ session_data = record.data
88
+ if session_data && session_data.respond_to?(:each_value)
89
+ session_data.each_value do |obj|
90
+ obj.clear_association_cache if obj.respond_to?(:clear_association_cache)
88
91
  end
89
-
90
- sid
91
92
  end
92
- end
93
93
 
94
- def destroy_session(env, session_id, options)
95
- logger.silence_logger do
96
- if sid = current_session_id(env)
97
- get_session_model(env, sid).destroy
98
- env[SESSION_RECORD_KEY] = nil
99
- end
94
+ sid
95
+ end
96
+ end
100
97
 
101
- generate_sid unless options[:drop]
98
+ def delete_session(request, session_id, options)
99
+ logger.silence_logger do
100
+ if sid = current_session_id(request)
101
+ get_session_model(request, sid).destroy
102
+ request.env[SESSION_RECORD_KEY] = nil
102
103
  end
104
+ generate_sid unless options[:drop]
103
105
  end
106
+ end
104
107
 
105
- def get_session_model(env, sid)
106
- if env[ENV_SESSION_OPTIONS_KEY][:id].nil?
107
- env[SESSION_RECORD_KEY] = find_session(sid)
108
+ def get_session_model(request, id)
109
+ logger.silence_logger do
110
+ model = @@session_class.find_by_session_id(id)
111
+ if !model
112
+ id = generate_sid
113
+ model = @@session_class.new(:session_id => id, :data => {})
114
+ model.save
115
+ end
116
+ if request.env[ENV_SESSION_OPTIONS_KEY][:id].nil?
117
+ request.env[SESSION_RECORD_KEY] = model
108
118
  else
109
- env[SESSION_RECORD_KEY] ||= find_session(sid)
119
+ request.env[SESSION_RECORD_KEY] ||= model
110
120
  end
121
+ model
111
122
  end
123
+ end
112
124
 
113
- def find_session(id)
114
- @@session_class.find_by_session_id(id) ||
115
- @@session_class.new(:session_id => id, :data => {})
116
- end
125
+ def find_session(request, id)
126
+ model = get_session_model(request, id)
127
+ [model.session_id, model.data]
128
+ end
117
129
 
118
- def logger
119
- ActiveRecord::Base.logger || ActiveRecord::SessionStore::NilLogger
120
- end
130
+ def logger
131
+ ActiveRecord::Base.logger || ActiveRecord::SessionStore::NilLogger
132
+ end
121
133
  end
122
134
  end
123
135
  end
136
+
137
+ if ActiveRecord::VERSION::MAJOR == 4
138
+ require 'action_dispatch/session/legacy_support'
139
+ ActionDispatch::Session::ActiveRecordStore.send(:include, ActionDispatch::Session::LegacySupport)
140
+ end
@@ -0,0 +1,51 @@
1
+ module ActionDispatch
2
+ module Session
3
+ module LegacySupport
4
+ EnvWrapper = Struct.new(:env)
5
+
6
+ def self.included(klass)
7
+ [
8
+ :get_session,
9
+ :get_session_model,
10
+ :write_session,
11
+ :delete_session,
12
+ :find_session
13
+ ].each do |m|
14
+ klass.send(:alias_method, "#{m}_rails5".to_sym, m)
15
+ klass.send(:remove_method, m)
16
+ end
17
+ end
18
+
19
+ def get_session(env, sid)
20
+ request = EnvWrapper.new(env)
21
+ get_session_rails5(request, sid)
22
+ end
23
+
24
+ def set_session(env, sid, session_data, options)
25
+ request = EnvWrapper.new(env)
26
+ write_session_rails5(request, sid, session_data, options)
27
+ end
28
+
29
+ def destroy_session(env, session_id, options)
30
+ request = EnvWrapper.new(env)
31
+ if sid = current_session_id(request.env)
32
+ get_session_model(request, sid).destroy
33
+ request.env[self.class::SESSION_RECORD_KEY] = nil
34
+ end
35
+ generate_sid unless options[:drop]
36
+ end
37
+
38
+ def get_session_model(request, sid)
39
+ if request.env[self.class::ENV_SESSION_OPTIONS_KEY][:id].nil?
40
+ request.env[self.class::SESSION_RECORD_KEY] = find_session(sid)
41
+ else
42
+ request.env[self.class::SESSION_RECORD_KEY] ||= find_session(sid)
43
+ end
44
+ end
45
+
46
+ def find_session(id)
47
+ self.class.session_class.find_by_session_id(id) || self.class.session_class.new(:session_id => id, :data => {})
48
+ end
49
+ end
50
+ end
51
+ end
@@ -13,12 +13,20 @@ module ActiveRecord
13
13
  end
14
14
 
15
15
  def drop_table!
16
- connection.schema_cache.clear_table_cache!(table_name)
16
+ if connection.schema_cache.respond_to?(:clear_data_source_cache!)
17
+ connection.schema_cache.clear_data_source_cache!(table_name)
18
+ else
19
+ connection.schema_cache.clear_table_cache!(table_name)
20
+ end
17
21
  connection.drop_table table_name
18
22
  end
19
23
 
20
24
  def create_table!
21
- connection.schema_cache.clear_table_cache!(table_name)
25
+ if connection.schema_cache.respond_to?(:clear_data_source_cache!)
26
+ connection.schema_cache.clear_data_source_cache!(table_name)
27
+ else
28
+ connection.schema_cache.clear_table_cache!(table_name)
29
+ end
22
30
  connection.create_table(table_name) do |t|
23
31
  t.string session_id_column, :limit => 255
24
32
  t.text data_column_name
@@ -13,8 +13,10 @@ module ActiveRecord
13
13
  included do
14
14
  cattr_accessor :silencer
15
15
  self.silencer = true
16
- alias_method_chain :level, :threadsafety
17
- alias_method_chain :add, :threadsafety
16
+ alias_method :level_without_threadsafety, :level
17
+ alias_method :level, :level_with_threadsafety
18
+ alias_method :add_without_threadsafety, :add
19
+ alias_method :add, :add_with_threadsafety
18
20
  end
19
21
 
20
22
  def thread_level
@@ -30,7 +32,7 @@ module ActiveRecord
30
32
  end
31
33
 
32
34
  def add_with_threadsafety(severity, message = nil, progname = nil, &block)
33
- if !defined?(@logdev) || @logdev.nil? || (severity || UNKNOWN) < level
35
+ if (defined?(@logdev) && @logdev.nil?) || (severity || UNKNOWN) < level
34
36
  true
35
37
  else
36
38
  add_without_threadsafety(severity, message, progname, &block)
@@ -1,10 +1,12 @@
1
1
  require "active_support/core_ext/module/attribute_accessors"
2
+ require "thread"
2
3
 
3
4
  module ActiveRecord
4
5
  module SessionStore
5
6
  # The default Active Record class.
6
7
  class Session < ActiveRecord::Base
7
8
  extend ClassMethods
9
+ SEMAPHORE = Mutex.new
8
10
 
9
11
  ##
10
12
  # :singleton-method:
@@ -29,7 +31,7 @@ module ActiveRecord
29
31
 
30
32
  # Hook to set up sessid compatibility.
31
33
  def find_by_session_id(session_id)
32
- Thread.exclusive { setup_sessid_compatibility! }
34
+ SEMAPHORE.synchronize { setup_sessid_compatibility! }
33
35
  find_by_session_id(session_id)
34
36
  end
35
37
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-session_store
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 1.0.0.pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Heinemeier Hansson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-06 00:00:00.000000000 Z
11
+ date: 2016-04-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -16,60 +16,80 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 4.0.0
19
+ version: '4.0'
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '5'
22
+ version: '5.1'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: 4.0.0
29
+ version: '4.0'
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '5'
32
+ version: '5.1'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: actionpack
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
37
  - - ">="
38
38
  - !ruby/object:Gem::Version
39
- version: 4.0.0
39
+ version: '4.0'
40
40
  - - "<"
41
41
  - !ruby/object:Gem::Version
42
- version: '5'
42
+ version: '5.1'
43
43
  type: :runtime
44
44
  prerelease: false
45
45
  version_requirements: !ruby/object:Gem::Requirement
46
46
  requirements:
47
47
  - - ">="
48
48
  - !ruby/object:Gem::Version
49
- version: 4.0.0
49
+ version: '4.0'
50
50
  - - "<"
51
51
  - !ruby/object:Gem::Version
52
- version: '5'
52
+ version: '5.1'
53
53
  - !ruby/object:Gem::Dependency
54
54
  name: railties
55
55
  requirement: !ruby/object:Gem::Requirement
56
56
  requirements:
57
57
  - - ">="
58
58
  - !ruby/object:Gem::Version
59
- version: 4.0.0
59
+ version: '4.0'
60
60
  - - "<"
61
61
  - !ruby/object:Gem::Version
62
- version: '5'
62
+ version: '5.1'
63
63
  type: :runtime
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
66
66
  requirements:
67
67
  - - ">="
68
68
  - !ruby/object:Gem::Version
69
- version: 4.0.0
69
+ version: '4.0'
70
70
  - - "<"
71
71
  - !ruby/object:Gem::Version
72
- version: '5'
72
+ version: '5.1'
73
+ - !ruby/object:Gem::Dependency
74
+ name: rack
75
+ requirement: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: 1.5.2
80
+ - - "<"
81
+ - !ruby/object:Gem::Version
82
+ version: '3'
83
+ type: :runtime
84
+ prerelease: false
85
+ version_requirements: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: 1.5.2
90
+ - - "<"
91
+ - !ruby/object:Gem::Version
92
+ version: '3'
73
93
  - !ruby/object:Gem::Dependency
74
94
  name: sqlite3
75
95
  requirement: !ruby/object:Gem::Requirement
@@ -88,16 +108,16 @@ dependencies:
88
108
  name: appraisal
89
109
  requirement: !ruby/object:Gem::Requirement
90
110
  requirements:
91
- - - ">="
111
+ - - "~>"
92
112
  - !ruby/object:Gem::Version
93
- version: '0'
113
+ version: 2.1.0
94
114
  type: :development
95
115
  prerelease: false
96
116
  version_requirements: !ruby/object:Gem::Requirement
97
117
  requirements:
98
- - - ">="
118
+ - - "~>"
99
119
  - !ruby/object:Gem::Version
100
- version: '0'
120
+ version: 2.1.0
101
121
  description:
102
122
  email: david@loudthinking.com
103
123
  executables: []
@@ -108,6 +128,7 @@ files:
108
128
  - MIT-LICENSE
109
129
  - README.md
110
130
  - lib/action_dispatch/session/active_record_store.rb
131
+ - lib/action_dispatch/session/legacy_support.rb
111
132
  - lib/active_record/session_store.rb
112
133
  - lib/active_record/session_store/extension/logger_silencer.rb
113
134
  - lib/active_record/session_store/railtie.rb
@@ -134,12 +155,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
134
155
  version: 1.9.3
135
156
  required_rubygems_version: !ruby/object:Gem::Requirement
136
157
  requirements:
137
- - - ">="
158
+ - - ">"
138
159
  - !ruby/object:Gem::Version
139
- version: '0'
160
+ version: 1.3.1
140
161
  requirements: []
141
162
  rubyforge_project:
142
- rubygems_version: 2.4.5.1
163
+ rubygems_version: 2.5.1
143
164
  signing_key:
144
165
  specification_version: 4
145
166
  summary: An Action Dispatch session store backed by an Active Record class.