Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
c4f02295
R
rails
项目概览
张重言
/
rails
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rails
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
c4f02295
编写于
5月 03, 2012
作者:
A
Aaron Patterson
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
bread AD::Request::Session to it's own file, consolidate HASH OF DOOM lookups
上级
9aa5bb4b
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
171 addition
and
153 deletion
+171
-153
actionpack/lib/action_dispatch/http/request.rb
actionpack/lib/action_dispatch/http/request.rb
+3
-2
actionpack/lib/action_dispatch/middleware/flash.rb
actionpack/lib/action_dispatch/middleware/flash.rb
+1
-1
actionpack/lib/action_dispatch/middleware/session/abstract_store.rb
.../lib/action_dispatch/middleware/session/abstract_store.rb
+1
-150
actionpack/lib/action_dispatch/request/session.rb
actionpack/lib/action_dispatch/request/session.rb
+166
-0
未找到文件。
actionpack/lib/action_dispatch/http/request.rb
浏览文件 @
c4f02295
...
@@ -6,6 +6,7 @@
...
@@ -6,6 +6,7 @@
require
'active_support/core_ext/string/access'
require
'active_support/core_ext/string/access'
require
'active_support/inflector'
require
'active_support/inflector'
require
'action_dispatch/http/headers'
require
'action_dispatch/http/headers'
require
'action_dispatch/request/session'
require
'action_controller/metal/exceptions'
require
'action_controller/metal/exceptions'
module
ActionDispatch
module
ActionDispatch
...
@@ -220,11 +221,11 @@ def reset_session
...
@@ -220,11 +221,11 @@ def reset_session
end
end
def
session
=
(
session
)
#:nodoc:
def
session
=
(
session
)
#:nodoc:
@env
[
'rack.session'
]
=
session
Session
.
set
@env
,
session
end
end
def
session_options
=
(
options
)
def
session_options
=
(
options
)
@env
[
'rack.session.options'
]
=
options
Session
::
Options
.
set
@env
,
options
end
end
# Override Rack's GET method to support indifferent access
# Override Rack's GET method to support indifferent access
...
...
actionpack/lib/action_dispatch/middleware/flash.rb
浏览文件 @
c4f02295
...
@@ -218,7 +218,7 @@ def initialize(app)
...
@@ -218,7 +218,7 @@ def initialize(app)
def
call
(
env
)
def
call
(
env
)
@app
.
call
(
env
)
@app
.
call
(
env
)
ensure
ensure
session
=
env
[
'rack.session'
]
||
{}
session
=
Request
::
Session
.
find
(
env
)
||
{}
flash_hash
=
env
[
KEY
]
flash_hash
=
env
[
KEY
]
if
flash_hash
if
flash_hash
...
...
actionpack/lib/action_dispatch/middleware/session/abstract_store.rb
浏览文件 @
c4f02295
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
require
'rack/request'
require
'rack/request'
require
'rack/session/abstract/id'
require
'rack/session/abstract/id'
require
'action_dispatch/middleware/cookies'
require
'action_dispatch/middleware/cookies'
require
'action_dispatch/request/session'
require
'active_support/core_ext/object/blank'
require
'active_support/core_ext/object/blank'
module
ActionDispatch
module
ActionDispatch
...
@@ -84,154 +85,4 @@ def set_cookie(env, session_id, cookie)
...
@@ -84,154 +85,4 @@ def set_cookie(env, session_id, cookie)
end
end
end
end
end
end
class
Request
# SessionHash is responsible to lazily load the session from store.
class
Session
# :nodoc:
ENV_SESSION_KEY
=
Rack
::
Session
::
Abstract
::
ENV_SESSION_KEY
# :nodoc:
ENV_SESSION_OPTIONS_KEY
=
Rack
::
Session
::
Abstract
::
ENV_SESSION_OPTIONS_KEY
# :nodoc:
def
self
.
create
(
store
,
env
,
default_options
)
session_was
=
env
[
ENV_SESSION_KEY
]
session
=
Request
::
Session
.
new
(
store
,
env
)
env
[
ENV_SESSION_KEY
]
=
session
env
[
ENV_SESSION_OPTIONS_KEY
]
=
Request
::
Session
::
Options
.
new
(
store
,
env
,
default_options
)
env
[
ENV_SESSION_KEY
].
merge!
session_was
if
session_was
session
end
def
self
.
find
(
env
)
env
[
ENV_SESSION_KEY
]
end
class
Options
#:nodoc:
def
initialize
(
by
,
env
,
default_options
)
@by
=
by
@env
=
env
@delegate
=
default_options
end
def
[]
(
key
)
if
key
==
:id
@delegate
.
fetch
(
key
)
{
@delegate
[
:id
]
=
@by
.
send
(
:extract_session_id
,
@env
)
}
else
@delegate
[
key
]
end
end
def
[]=
(
k
,
v
);
@delegate
[
k
]
=
v
;
end
def
to_hash
;
@delegate
.
dup
;
end
def
values_at
(
*
args
);
@delegate
.
values_at
(
*
args
);
end
end
def
initialize
(
by
,
env
)
@by
=
by
@env
=
env
@delegate
=
{}
@loaded
=
false
@exists
=
nil
# we haven't checked yet
end
def
options
@env
[
ENV_SESSION_OPTIONS_KEY
]
end
def
destroy
clear
options
=
self
.
options
||
{}
@by
.
send
(
:destroy_session
,
@env
,
options
[
:id
],
options
)
options
[
:id
]
=
nil
@loaded
=
false
end
def
[]
(
key
)
load_for_read!
@delegate
[
key
.
to_s
]
end
def
has_key?
(
key
)
load_for_read!
@delegate
.
key?
(
key
.
to_s
)
end
alias
:key?
:has_key?
alias
:include?
:has_key?
def
[]=
(
key
,
value
)
load_for_write!
@delegate
[
key
.
to_s
]
=
value
end
def
clear
load_for_write!
@delegate
.
clear
end
def
to_hash
load_for_read!
@delegate
.
dup
.
delete_if
{
|
_
,
v
|
v
.
nil?
}
end
def
update
(
hash
)
load_for_write!
@delegate
.
update
stringify_keys
(
hash
)
end
def
delete
(
key
)
load_for_write!
@delegate
.
delete
key
.
to_s
end
def
inspect
if
loaded?
super
else
"#<
#{
self
.
class
}
:0x
#{
(
object_id
<<
1
).
to_s
(
16
)
}
not yet loaded>"
end
end
def
exists?
return
@exists
unless
@exists
.
nil?
@exists
=
@by
.
send
(
:session_exists?
,
@env
)
end
def
loaded?
@loaded
end
def
empty?
load_for_read!
@delegate
.
empty?
end
def
merge!
(
other
)
load_for_write!
@delegate
.
merge!
(
other
)
end
private
def
load_for_read!
load
!
if
!
loaded?
&&
exists?
end
def
load_for_write!
load
!
unless
loaded?
end
def
load!
id
,
session
=
@by
.
load_session
@env
options
[
:id
]
=
id
@delegate
.
replace
(
stringify_keys
(
session
))
@loaded
=
true
end
def
stringify_keys
(
other
)
other
.
each_with_object
({})
{
|
(
key
,
value
),
hash
|
hash
[
key
.
to_s
]
=
value
}
end
end
end
end
end
actionpack/lib/action_dispatch/request/session.rb
0 → 100644
浏览文件 @
c4f02295
require
'rack/session/abstract/id'
module
ActionDispatch
class
Request
<
Rack
::
Request
# SessionHash is responsible to lazily load the session from store.
class
Session
# :nodoc:
ENV_SESSION_KEY
=
Rack
::
Session
::
Abstract
::
ENV_SESSION_KEY
# :nodoc:
ENV_SESSION_OPTIONS_KEY
=
Rack
::
Session
::
Abstract
::
ENV_SESSION_OPTIONS_KEY
# :nodoc:
def
self
.
create
(
store
,
env
,
default_options
)
session_was
=
find
env
session
=
Request
::
Session
.
new
(
store
,
env
)
session
.
merge!
session_was
if
session_was
set
(
env
,
session
)
Options
.
set
(
env
,
Request
::
Session
::
Options
.
new
(
store
,
env
,
default_options
))
session
end
def
self
.
find
(
env
)
env
[
ENV_SESSION_KEY
]
end
def
self
.
set
(
env
,
session
)
env
[
ENV_SESSION_KEY
]
=
session
end
class
Options
#:nodoc:
def
self
.
set
(
env
,
options
)
env
[
ENV_SESSION_OPTIONS_KEY
]
=
options
end
def
self
.
find
(
env
)
env
[
ENV_SESSION_OPTIONS_KEY
]
end
def
initialize
(
by
,
env
,
default_options
)
@by
=
by
@env
=
env
@delegate
=
default_options
end
def
[]
(
key
)
if
key
==
:id
@delegate
.
fetch
(
key
)
{
@delegate
[
:id
]
=
@by
.
send
(
:extract_session_id
,
@env
)
}
else
@delegate
[
key
]
end
end
def
[]=
(
k
,
v
);
@delegate
[
k
]
=
v
;
end
def
to_hash
;
@delegate
.
dup
;
end
def
values_at
(
*
args
);
@delegate
.
values_at
(
*
args
);
end
end
def
initialize
(
by
,
env
)
@by
=
by
@env
=
env
@delegate
=
{}
@loaded
=
false
@exists
=
nil
# we haven't checked yet
end
def
options
Options
.
find
@env
end
def
destroy
clear
options
=
self
.
options
||
{}
@by
.
send
(
:destroy_session
,
@env
,
options
[
:id
],
options
)
options
[
:id
]
=
nil
@loaded
=
false
end
def
[]
(
key
)
load_for_read!
@delegate
[
key
.
to_s
]
end
def
has_key?
(
key
)
load_for_read!
@delegate
.
key?
(
key
.
to_s
)
end
alias
:key?
:has_key?
alias
:include?
:has_key?
def
[]=
(
key
,
value
)
load_for_write!
@delegate
[
key
.
to_s
]
=
value
end
def
clear
load_for_write!
@delegate
.
clear
end
def
to_hash
load_for_read!
@delegate
.
dup
.
delete_if
{
|
_
,
v
|
v
.
nil?
}
end
def
update
(
hash
)
load_for_write!
@delegate
.
update
stringify_keys
(
hash
)
end
def
delete
(
key
)
load_for_write!
@delegate
.
delete
key
.
to_s
end
def
inspect
if
loaded?
super
else
"#<
#{
self
.
class
}
:0x
#{
(
object_id
<<
1
).
to_s
(
16
)
}
not yet loaded>"
end
end
def
exists?
return
@exists
unless
@exists
.
nil?
@exists
=
@by
.
send
(
:session_exists?
,
@env
)
end
def
loaded?
@loaded
end
def
empty?
load_for_read!
@delegate
.
empty?
end
def
merge!
(
other
)
load_for_write!
@delegate
.
merge!
(
other
)
end
private
def
load_for_read!
load
!
if
!
loaded?
&&
exists?
end
def
load_for_write!
load
!
unless
loaded?
end
def
load!
id
,
session
=
@by
.
load_session
@env
options
[
:id
]
=
id
@delegate
.
replace
(
stringify_keys
(
session
))
@loaded
=
true
end
def
stringify_keys
(
other
)
other
.
each_with_object
({})
{
|
(
key
,
value
),
hash
|
hash
[
key
.
to_s
]
=
value
}
end
end
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录