thoughtbot/clearance — pull request #366 by derekprior (2013-10-11 19:22:32+00:00)
Title: Enable simpler implementation of `remember me`

The lambda for `Clearance.configuration.cookie_expiration` can now optionally
take an argument. If that argument is present, `session` will call the
configured lamdba passing the entire collection of cookies available in
session. This allows implementation of remember_me without monkey-patching
clearance.

Anyone wanting to implement remember_me would now:

* add the remember_me checkbox to the login form.
* override sessions_controller create to set the remember_me cookie, like so:

``` def create
set_remember_me
super end

private

def set_remember_me
if params[:remember_me]
cookies.permanent[:remember_me] = true
else
cookies.delete(:remember_me)
end end
```

* Configure clearance using something like this:

``` config.cookie_expiration = ->(cookies) do
if cookies['remember_me']?
1.year.from_now
else
nil
end end
```

The last two steps could conceivable be extracted to their own gem to make
this simpler, if desired.