提交 0e0cff0f 编写于 作者: K Kasper Timm Hansen

Replace implicit formats with a case statement.

The coder that Psych passes in has a `tag` method we can use to detect
which serialization format we're reviving for. Use it and make it clearer
alongside the `load_tags` fiddling.
上级 6eb97823
......@@ -601,19 +601,20 @@ def inspect
end
def init_with(coder) # :nodoc:
if coder.map['elements']
# YAML 2.0.9's Hash subclass format from Rails 4.2, where keys and values
case coder.tag
when '!ruby/hash:ActionController::Parameters'
# YAML 2.0.8's format where hash instance variables weren't stored.
@parameters = coder.map.with_indifferent_access
@permitted = false
when '!ruby/hash-with-ivars:ActionController::Parameters'
# YAML 2.0.9's Hash subclass format where keys and values
# were stored under an elements hash and `permitted` within an ivars hash.
@parameters = coder.map['elements'].with_indifferent_access
@permitted = coder.map['ivars'][:@permitted]
elsif coder.map['parameters']
when '!ruby/object:ActionController::Parameters'
# YAML's Object format. Only needed because of the format
# backwardscompability above, otherwise equivalent to YAML's initialization.
@parameters, @permitted = coder.map['parameters'], coder.map['permitted']
else
# YAML 2.0.8's format where hash instance variables weren't stored.
@parameters = coder.map.with_indifferent_access
@permitted = false
end
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册