Define derived metadata.

This fixes #969 and supercedes #1089.

Not ready for merge yet (or even at a point where I'd ask it to be reviewed)...I'm pushing this so I can make an rspec-rails PR that depends on this.