activerecord-session_store 0.1.0 → 0.1.1.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: 0ea10b5f92d5818f9ae6951c3f54116acb119eae
4
- data.tar.gz: ce9c39fbef8fbdc82ca36a732948bee2939e8a64
3
+ metadata.gz: adf05ad9dc9399cb9ff6b312bf79b0da4119f7f4
4
+ data.tar.gz: b2bf84d11f05d675b4e68fc3cc96c5fa71a52775
5
5
  SHA512:
6
- metadata.gz: 0dedb0c1303059ef56c5181b2a284eb051acb0103b2d71f14440c61f042bba754563fd3a2d38d6e5f9eeab35c14968377c9cbb7534c7cabda72c22a77549a72c
7
- data.tar.gz: 2b72be9257bf89fbac1eef9f82f9a703e29f5dc83a9021c0a0ad8baf4c9496cf3f8ab8dea5ab80592822d03222b4e1b005968c47e4a2bb6f677c0037b840be1c
6
+ metadata.gz: af07b4aeddd875b6e9c1d05cb98ed12bfc5b2dfef08c9254d18654ff462821bd073e47e90c733026c8da40034861824d3560f11feb436296e818c62771c85951
7
+ data.tar.gz: a926c8686c220de2636287b575238d694be509deb46181abe510080849b50aa44bc57bbc857495dbb558a8ec3948d7f8caac9bad560ac4cf1121e8018a58a80a
data/README.md CHANGED
@@ -10,7 +10,9 @@ Installation
10
10
 
11
11
  Include this gem into your Gemfile:
12
12
 
13
- gem 'activerecord-session_store', github: 'rails/activerecord-session_store'
13
+ ```ruby
14
+ gem 'activerecord-session_store'
15
+ ```
14
16
 
15
17
  Run the migration generator:
16
18
 
@@ -18,7 +20,9 @@ Run the migration generator:
18
20
 
19
21
  Then, set your session store in `config/initializers/session_store.rb`:
20
22
 
21
- Foo::Application.config.session_store :active_record_store
23
+ ```ruby
24
+ Foo::Application.config.session_store :active_record_store
25
+ ```
22
26
 
23
27
  Configuration
24
28
  --------------
@@ -37,9 +41,11 @@ ActionController::SessionOverflowError will be raised.
37
41
  You may configure the table name, primary key, and data column.
38
42
  For example, at the end of `config/application.rb`:
39
43
 
40
- ActiveRecord::SessionStore::Session.table_name = 'legacy_session_table'
41
- ActiveRecord::SessionStore::Session.primary_key = 'session_id'
42
- ActiveRecord::SessionStore::Session.data_column_name = 'legacy_session_data'
44
+ ```ruby
45
+ ActiveRecord::SessionStore::Session.table_name = 'legacy_session_table'
46
+ ActiveRecord::SessionStore::Session.primary_key = 'session_id'
47
+ ActiveRecord::SessionStore::Session.data_column_name = 'legacy_session_data'
48
+ ```
43
49
 
44
50
  Note that setting the primary key to the `session_id` frees you from
45
51
  having a separate `id` column if you don't want it. However, you must
@@ -53,8 +59,10 @@ the `sessions` table, making periodic session expiration a snap.
53
59
  You may provide your own session class implementation, whether a
54
60
  feature-packed Active Record or a bare-metal high-performance SQL
55
61
  store, by setting
56
-
57
- ActionDispatch::Session::ActiveRecordStore.session_class = MySessionClass
62
+
63
+ ```ruby
64
+ ActionDispatch::Session::ActiveRecordStore.session_class = MySessionClass
65
+ ```
58
66
 
59
67
  You must implement these methods:
60
68
 
@@ -61,7 +61,7 @@ module ActionDispatch
61
61
 
62
62
  private
63
63
  def get_session(env, sid)
64
- ActiveRecord::Base.logger.quietly do
64
+ logger.silence do
65
65
  unless sid and session = @@session_class.find_by_session_id(sid)
66
66
  # If the sid was nil or if there is no pre-existing session under the sid,
67
67
  # force the generation of a new sid and associate a new session associated with the new sid
@@ -74,7 +74,7 @@ module ActionDispatch
74
74
  end
75
75
 
76
76
  def set_session(env, sid, session_data, options)
77
- ActiveRecord::Base.logger.quietly do
77
+ logger.silence do
78
78
  record = get_session_model(env, sid)
79
79
  record.data = session_data
80
80
  return false unless record.save
@@ -85,20 +85,20 @@ module ActionDispatch
85
85
  obj.clear_association_cache if obj.respond_to?(:clear_association_cache)
86
86
  end
87
87
  end
88
- end
89
88
 
90
- sid
89
+ sid
90
+ end
91
91
  end
92
92
 
93
93
  def destroy_session(env, session_id, options)
94
- if sid = current_session_id(env)
95
- ActiveRecord::Base.logger.quietly do
94
+ logger.silence do
95
+ if sid = current_session_id(env)
96
96
  get_session_model(env, sid).destroy
97
97
  env[SESSION_RECORD_KEY] = nil
98
98
  end
99
- end
100
99
 
101
- generate_sid unless options[:drop]
100
+ generate_sid unless options[:drop]
101
+ end
102
102
  end
103
103
 
104
104
  def get_session_model(env, sid)
@@ -113,6 +113,10 @@ module ActionDispatch
113
113
  @@session_class.find_by_session_id(id) ||
114
114
  @@session_class.new(:session_id => id, :data => {})
115
115
  end
116
+
117
+ def logger
118
+ ActiveRecord::Base.logger || ActiveRecord::SessionStore::NilLogger
119
+ end
116
120
  end
117
121
  end
118
122
  end
@@ -1,4 +1,5 @@
1
1
  require 'action_dispatch/session/active_record_store'
2
+ require "active_record/session_store/extension/logger_silencer"
2
3
 
3
4
  module ActiveRecord
4
5
  module SessionStore
@@ -32,5 +33,5 @@ require 'active_record/session_store/session'
32
33
  require 'active_record/session_store/sql_bypass'
33
34
  require 'active_record/session_store/railtie' if defined?(Rails)
34
35
 
35
-
36
36
  ActionDispatch::Session::ActiveRecordStore.session_class = ActiveRecord::SessionStore::Session
37
+ Logger.send :include, ActiveRecord::SessionStore::Extension::LoggerSilencer
@@ -0,0 +1,72 @@
1
+ require "thread"
2
+ require "active_support/core_ext/class/attribute_accessors"
3
+ require "active_support/core_ext/module/aliasing"
4
+ require "active_support/concern"
5
+
6
+ module ActiveRecord
7
+ module SessionStore
8
+ module Extension
9
+ module LoggerSilencer
10
+ extend ActiveSupport::Concern
11
+
12
+ included do
13
+ cattr_accessor :silencer
14
+ self.silencer = true
15
+ alias_method_chain :level, :threadsafety
16
+ alias_method_chain :add, :threadsafety
17
+ end
18
+
19
+ def thread_level
20
+ Thread.current[thread_hash_level_key]
21
+ end
22
+
23
+ def thread_level=(level)
24
+ Thread.current[thread_hash_level_key] = level
25
+ end
26
+
27
+ def level_with_threadsafety
28
+ thread_level || level_without_threadsafety
29
+ end
30
+
31
+ def add_with_threadsafety(severity, message = nil, progname = nil, &block)
32
+ return true if @logdev.nil? or (severity || UNKNOWN) < level
33
+ add_without_threadsafety(severity, message, progname, &block)
34
+ end
35
+
36
+ # Silences the logger for the duration of the block.
37
+ def silence(temporary_level = Logger::ERROR)
38
+ if silencer
39
+ begin
40
+ self.thread_level = temporary_level
41
+ yield self
42
+ ensure
43
+ self.thread_level = nil
44
+ end
45
+ else
46
+ yield self
47
+ end
48
+ end
49
+
50
+ for severity in Logger::Severity.constants
51
+ class_eval <<-EOT, __FILE__, __LINE__ + 1
52
+ def #{severity.downcase}? # def debug?
53
+ Logger::#{severity} >= level # DEBUG >= level
54
+ end # end
55
+ EOT
56
+ end
57
+
58
+ private
59
+
60
+ def thread_hash_level_key
61
+ @thread_hash_level_key ||= :"ThreadSafeLogger##{object_id}@level"
62
+ end
63
+ end
64
+ end
65
+
66
+ class NilLogger
67
+ def self.silence
68
+ yield
69
+ end
70
+ end
71
+ end
72
+ end
metadata CHANGED
@@ -1,87 +1,101 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-session_store
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1.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: 2013-10-24 00:00:00.000000000 Z
11
+ date: 2015-01-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: 4.0.0
20
- - - <
20
+ - - "<"
21
21
  - !ruby/object:Gem::Version
22
22
  version: '5'
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
29
  version: 4.0.0
30
- - - <
30
+ - - "<"
31
31
  - !ruby/object:Gem::Version
32
32
  version: '5'
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
39
  version: 4.0.0
40
- - - <
40
+ - - "<"
41
41
  - !ruby/object:Gem::Version
42
42
  version: '5'
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
49
  version: 4.0.0
50
- - - <
50
+ - - "<"
51
51
  - !ruby/object:Gem::Version
52
52
  version: '5'
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
59
  version: 4.0.0
60
- - - <
60
+ - - "<"
61
61
  - !ruby/object:Gem::Version
62
62
  version: '5'
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
69
  version: 4.0.0
70
- - - <
70
+ - - "<"
71
71
  - !ruby/object:Gem::Version
72
72
  version: '5'
73
73
  - !ruby/object:Gem::Dependency
74
74
  name: sqlite3
75
75
  requirement: !ruby/object:Gem::Requirement
76
76
  requirements:
77
- - - '>='
77
+ - - ">="
78
78
  - !ruby/object:Gem::Version
79
79
  version: '0'
80
80
  type: :development
81
81
  prerelease: false
82
82
  version_requirements: !ruby/object:Gem::Requirement
83
83
  requirements:
84
- - - '>='
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ - !ruby/object:Gem::Dependency
88
+ name: appraisal
89
+ requirement: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ type: :development
95
+ prerelease: false
96
+ version_requirements: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
85
99
  - !ruby/object:Gem::Version
86
100
  version: '0'
87
101
  description:
@@ -93,10 +107,11 @@ extra_rdoc_files:
93
107
  files:
94
108
  - README.md
95
109
  - lib/action_dispatch/session/active_record_store.rb
110
+ - lib/active_record/session_store.rb
111
+ - lib/active_record/session_store/extension/logger_silencer.rb
96
112
  - lib/active_record/session_store/railtie.rb
97
113
  - lib/active_record/session_store/session.rb
98
114
  - lib/active_record/session_store/sql_bypass.rb
99
- - lib/active_record/session_store.rb
100
115
  - lib/activerecord/session_store.rb
101
116
  - lib/generators/active_record/session_migration_generator.rb
102
117
  - lib/generators/active_record/templates/migration.rb
@@ -107,24 +122,25 @@ licenses:
107
122
  metadata: {}
108
123
  post_install_message:
109
124
  rdoc_options:
110
- - --main
125
+ - "--main"
111
126
  - README.md
112
127
  require_paths:
113
128
  - lib
114
129
  required_ruby_version: !ruby/object:Gem::Requirement
115
130
  requirements:
116
- - - '>='
131
+ - - ">="
117
132
  - !ruby/object:Gem::Version
118
133
  version: 1.9.3
119
134
  required_rubygems_version: !ruby/object:Gem::Requirement
120
135
  requirements:
121
- - - '>='
136
+ - - ">"
122
137
  - !ruby/object:Gem::Version
123
- version: '0'
138
+ version: 1.3.1
124
139
  requirements: []
125
140
  rubyforge_project:
126
- rubygems_version: 2.0.6
141
+ rubygems_version: 2.4.5
127
142
  signing_key:
128
143
  specification_version: 4
129
144
  summary: An Action Dispatch session store backed by an Active Record class.
130
145
  test_files: []
146
+ has_rdoc: