CARVIEW |
Select Language
HTTP/2 302
server: nginx
date: Sun, 31 Aug 2025 06:56:22 GMT
content-type: text/plain; charset=utf-8
content-length: 0
x-archive-redirect-reason: found capture at 20090216231317
location: https://web.archive.org/web/20090216231317/https://github.com/thoughtbot/when/tree
server-timing: captures_list;dur=1.282437, exclusion.robots;dur=0.045316, exclusion.robots.policy;dur=0.026460, esindex;dur=0.016822, cdx.remote;dur=8.851074, LoadShardBlock;dur=319.066641, PetaboxLoader3.datanode;dur=176.292382, PetaboxLoader3.resolve;dur=92.680971
x-app-server: wwwb-app201
x-ts: 302
x-tr: 384
server-timing: TR;dur=0,Tw;dur=0,Tc;dur=1
set-cookie: wb-p-SERVER=wwwb-app201; path=/
x-location: All
x-rl: 0
x-na: 0
x-page-cache: MISS
server-timing: MISS
x-nid: DigitalOcean
referrer-policy: no-referrer-when-downgrade
permissions-policy: interest-cohort=()
HTTP/2 301
server: nginx
date: Sun, 31 Aug 2025 06:56:22 GMT
content-type: text/html; charset=utf-8
content-length: 111
x-archive-orig-server: nginx/0.6.26
x-archive-orig-date: Mon, 16 Feb 2009 23:13:17 GMT
x-archive-orig-connection: close
x-archive-orig-status: 301 Moved Permanently
location: https://web.archive.org/web/20090216231317/https://github.com/thoughtbot/when/tree/master
x-archive-orig-x-runtime: 19ms
x-archive-orig-cache-control: no-cache
x-archive-orig-content-length: 111
cache-control: max-age=1800
memento-datetime: Mon, 16 Feb 2009 23:13:17 GMT
link: ; rel="original", ; rel="timemap"; type="application/link-format", ; rel="timegate", ; rel="first memento"; datetime="Fri, 29 Aug 2008 18:54:00 GMT", ; rel="prev memento"; datetime="Tue, 30 Sep 2008 20:19:05 GMT", ; rel="memento"; datetime="Mon, 16 Feb 2009 23:13:17 GMT", ; rel="last memento"; datetime="Mon, 16 Feb 2009 23:13:17 GMT"
content-security-policy: default-src 'self' 'unsafe-eval' 'unsafe-inline' data: blob: archive.org web.archive.org web-static.archive.org wayback-api.archive.org athena.archive.org analytics.archive.org pragma.archivelab.org wwwb-events.archive.org
x-archive-src: 52_8_20090216213739_crawl102-c/52_8_20090216231246_crawl101.arc.gz
server-timing: captures_list;dur=0.627228, exclusion.robots;dur=0.026727, exclusion.robots.policy;dur=0.015474, esindex;dur=0.013258, cdx.remote;dur=10.596676, LoadShardBlock;dur=124.922488, PetaboxLoader3.datanode;dur=173.668254, PetaboxLoader3.resolve;dur=127.335635, load_resource;dur=181.800510
x-app-server: wwwb-app201
x-ts: 301
x-tr: 342
server-timing: TR;dur=0,Tw;dur=0,Tc;dur=1
x-location: All
x-rl: 0
x-na: 0
x-page-cache: MISS
server-timing: MISS
x-nid: DigitalOcean
referrer-policy: no-referrer-when-downgrade
permissions-policy: interest-cohort=()
HTTP/2 200
server: nginx
date: Sun, 31 Aug 2025 06:56:23 GMT
content-type: text/html; charset=utf-8
x-archive-orig-server: nginx/0.6.31
x-archive-orig-date: Mon, 16 Feb 2009 23:13:17 GMT
x-archive-orig-connection: close
x-archive-orig-status: 200 OK
x-archive-orig-x-runtime: 151ms
x-archive-orig-etag: "415866bd66cca877873cb90a2eee2d12"
x-archive-orig-cache-control: private, max-age=0, must-revalidate
x-archive-orig-content-length: 21041
x-archive-guessed-content-type: text/html
x-archive-guessed-charset: utf-8
memento-datetime: Mon, 16 Feb 2009 23:13:17 GMT
link: ; rel="original", ; rel="timemap"; type="application/link-format", ; rel="timegate", ; rel="first memento"; datetime="Sat, 26 Apr 2008 22:07:54 GMT", ; rel="prev memento"; datetime="Thu, 12 Feb 2009 16:13:28 GMT", ; rel="memento"; datetime="Mon, 16 Feb 2009 23:13:17 GMT", ; rel="next memento"; datetime="Sun, 15 Mar 2009 07:15:35 GMT", ; rel="last memento"; datetime="Wed, 14 Nov 2012 19:51:39 GMT"
content-security-policy: default-src 'self' 'unsafe-eval' 'unsafe-inline' data: blob: archive.org web.archive.org web-static.archive.org wayback-api.archive.org athena.archive.org analytics.archive.org pragma.archivelab.org wwwb-events.archive.org
x-archive-src: 52_8_20090216213739_crawl102-c/52_8_20090216231246_crawl101.arc.gz
server-timing: captures_list;dur=0.468632, exclusion.robots;dur=0.021563, exclusion.robots.policy;dur=0.012799, esindex;dur=0.008898, cdx.remote;dur=5.871080, LoadShardBlock;dur=419.164697, PetaboxLoader3.datanode;dur=255.624528, PetaboxLoader3.resolve;dur=201.908280, load_resource;dur=70.442741
x-app-server: wwwb-app201
x-ts: 200
x-tr: 553
server-timing: TR;dur=0,Tw;dur=0,Tc;dur=0
x-location: All
x-rl: 0
x-na: 0
x-page-cache: MISS
server-timing: MISS
x-nid: DigitalOcean
referrer-policy: no-referrer-when-downgrade
permissions-policy: interest-cohort=()
content-encoding: gzip
thoughtbot's when at master - GitHub
This repository is private.
All pages are served over SSL and all pushing and pulling is done over SSH.
No one may fork, clone, or view it unless they are added as a member.
Every repository with this icon (
) is private.
Every repository with this icon (

This repository is public.
Anyone may fork, clone, or view it.
Every repository with this icon (
) is public.
Every repository with this icon (

Description: | Conditional checks on Rails filters. The same functionality was added to Rails 2.1, so this is only necessary for pre-Rails 2.1 apps. |
Clone URL: |
git://github.com/thoughtbot/when.git
Give this clone URL to anyone.
git clone git://github.com/thoughtbot/when.git
|

dcroak (author)
Mon Feb 18 22:14:25 -0800 2008
when /
name | age | message | |
---|---|---|---|
![]() |
MIT-LICENSE | Wed Feb 13 16:25:45 -0800 2008 | updated the README [jcarroll] |
![]() |
README | Fri Feb 15 08:07:43 -0800 2008 | README message about Obsoleteness [dcroak] |
![]() |
Rakefile | Mon Feb 11 18:43:52 -0800 2008 | test and README files [dcroak] |
![]() |
init.rb | Mon Feb 11 22:32:55 -0800 2008 | refactoring tests [dcroak] |
![]() |
install.rb | Mon Feb 11 18:23:48 -0800 2008 | added when plugin skeleton [dcroak] |
![]() |
lib/ | Thu Feb 14 21:36:09 -0800 2008 | fixed callbacks String condition [jcarroll] |
![]() |
test/ | Mon Feb 18 22:14:25 -0800 2008 | made the string change to constants [dcroak] |
![]() |
uninstall.rb | Mon Feb 11 18:23:48 -0800 2008 | added when plugin skeleton [dcroak] |
When ==== When adds :if and :unless conditions to ActiveRecord callbacks and validations and ActionController filters. It works exactly the way as the current implementation of #validates_acceptance_of. It works on the 12 regular callbacks: before_validation before_validation_on_create after_validation after_validation_on_create before_save before_create before_update after_create after_update after_save before_destroy after_destroy 3 validations: validate validate_on_create validate_on_update and 1 filter: before_filter It works when :if or :unless is passed a Symbol, a Proc or a String. They return or evaluate to a true or false value. Example ======= class Address < ActiveRecord::Base before_save :geolocate def geolocate if complete? ... end end def complete? street? && city? && state? && zip? end end In this case, we want to find the latitude and longitude of an address only if the address is complete. Wrapping the entirety of a callback method with conditional logic is bad form. The callback should execute WHEN the model's life cycle reaches its "before_save" point and WHEN its address is "complete." With When, the WHEN responsibility is moved to where it belongs: as part of the callback. class Address < ActiveRecord::Base before_save :geolocate, :if => :complete? def geolocate ... end def complete? street? && city? && state? && zip? end end before_create's single responsibility is to execute code WHEN certain conditions are met. geolocate's single responsibility is to ... geolocate. It should not contain its own preconditions. More Examples ============= before_create :encrypt_password, :unless => lambda {|user| user.password_confirmation.blank?} before_filter :log_in!, :only => [:new, :create], :unless => :logged_in? What When does NOT support ========================== # ActiveRecord Class callbacks before_create PasswordEncryptor, :unless => lambda {|user| user.password_confirmation.blank?} # ActionController Class filters before_filter Authorizer, :unless => :logged_in? When will not work if your code contains any of these. In our experience we've never used class callbacks or filters and find them to be overkill. Obsolete after Rails 2.0.3 ========================== Whenever the next release after Rails 2.0.2 comes out, this feature will be baked into Rails via the ActiveSupport::Callbacks module. Happy coding! Installation ============ piston import https://svn.thoughtbot.com/plugins/when/trunk vendor/plugins/when Copyright (c) 2008 Jared Carroll, Dan Croak, and thoughtbot, inc. released under the MIT license
This feature is coming soon. Sit tight!