1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/actionpack/lib/action_dispatch
claudiob 398267b142
Add #dig to ActionDispatch::Request::Session
### Summary

The `session` object is not a real Hash but responds to many methods of Hash
such as `[]`, `[]`, `fetch`, `has_key?`.

Since Ruby 2.3, Hash also supports a `dig` method.

This commit adds a `dig` method to `ActionDispatch::Request::Session` with the
same behavior as `Hash#dig`.

This is useful if you store a hash in your session, such as:

```ruby
session[:user] = { id: 1, avatar_url: "http://example.org/nyancat.jpg" }
```

Then you can shorten your code from `session[:user][:avatar_url]` to `session.dig :user, :avatar_url`.

### Other Information

I cherry-picked a commit from https://github.com/rails/rails/pull/23864, and modify a bit.
The changes are below:

* Converts only the first key to a string adjust to the `fetch` method.
* Fixes a test case because we cannot use the indifferent access since ee5b621e2f.
2018-04-04 16:20:16 +09:00
..
http Add support for automatic nonce generation for Rails UJS 2018-02-19 15:59:34 +00:00
journey Fix array routing constraints 2018-02-17 02:44:58 +02:00
middleware Use ASCII-8BIT paths in ActionDispatch::Static 2018-03-22 04:23:49 +00:00
request Add #dig to ActionDispatch::Request::Session 2018-04-04 16:20:16 +09:00
routing Small doc fixes 2018-04-02 19:55:08 -04:00
system_testing Fix system tests transactions not closed between examples 2018-03-19 15:29:30 +02:00
testing
journey.rb
railtie.rb
routing.rb Improve docs of ActionDispatch::Routing 2018-03-13 11:56:33 +02:00
system_test_case.rb Allow Capybara 3.x (#32151) 2018-03-05 17:44:39 -08:00