diff options
author | Zachary Scott <e@zzak.io> | 2015-06-08 09:55:19 -0400 |
---|---|---|
committer | Zachary Scott <e@zzak.io> | 2015-06-08 09:55:19 -0400 |
commit | ed0677deafc8cbfe9850e91e8937d43e30ea26d3 (patch) | |
tree | d729019b3af27febf51fa61e9c239c05861c0b75 | |
parent | 90effb45a9e5004abbd6984008457075cc7bb089 (diff) | |
parent | 6709891c522c15cea9823c43df4d312ccc5423fd (diff) | |
download | rails-ed0677deafc8cbfe9850e91e8937d43e30ea26d3.tar.gz rails-ed0677deafc8cbfe9850e91e8937d43e30ea26d3.tar.bz2 rails-ed0677deafc8cbfe9850e91e8937d43e30ea26d3.zip |
Merge pull request #20470 from vngrs/add_missing_docs_for_action_dispatch_session
Add missing documentation for ActionDispatch::Request::Session [ci skip]
-rw-r--r-- | actionpack/lib/action_dispatch/request/session.rb | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/actionpack/lib/action_dispatch/request/session.rb b/actionpack/lib/action_dispatch/request/session.rb index 9a1a05e971..773d41de88 100644 --- a/actionpack/lib/action_dispatch/request/session.rb +++ b/actionpack/lib/action_dispatch/request/session.rb @@ -86,11 +86,14 @@ module ActionDispatch load_for_write! end + # Returns value of the key stored in the session or + # nil if the given key is not found in the session. def [](key) load_for_read! @delegate[key.to_s] end + # Returns true if the session has the given key or false. def has_key?(key) load_for_read! @delegate.key?(key.to_s) @@ -98,39 +101,69 @@ module ActionDispatch alias :key? :has_key? alias :include? :has_key? + # Returns keys of the session as Array. def keys @delegate.keys end + # Returns values of the session as Array. def values @delegate.values end + # Writes given value to given key of the session. def []=(key, value) load_for_write! @delegate[key.to_s] = value end + # Clears the session. def clear load_for_write! @delegate.clear end + # Returns the session as Hash. def to_hash load_for_read! @delegate.dup.delete_if { |_,v| v.nil? } end + # Updates the session with given Hash. + # + # session.to_hash + # # => {"session_id"=>"e29b9ea315edf98aad94cc78c34cc9b2"} + # + # session.update({ "foo" => "bar" }) + # # => {"session_id"=>"e29b9ea315edf98aad94cc78c34cc9b2", "foo" => "bar"} + # + # session.to_hash + # # => {"session_id"=>"e29b9ea315edf98aad94cc78c34cc9b2", "foo" => "bar"} def update(hash) load_for_write! @delegate.update stringify_keys(hash) end + # Deletes given key from the session. def delete(key) load_for_write! @delegate.delete key.to_s end + # Returns value of given key from the session, or raises +KeyError+ + # if can't find given key in case of not setted dafault value. + # Returns default value if specified. + # + # session.fetch(:foo) + # # => KeyError: key not found: "foo" + # + # session.fetch(:foo, :bar) + # # => :bar + # + # session.fetch(:foo) do + # :bar + # end + # # => :bar def fetch(key, default=Unspecified, &block) load_for_read! if default == Unspecified |