Created
June 20, 2013 21:10
-
-
Save theotherzach/5826681 to your computer and use it in GitHub Desktop.
I have become Brian Muller
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class User < ActiveRecord::Base | |
| geocoded_by :address | |
| def save_with_geocode | |
| geocode if address_changed? | |
| save | |
| end | |
| def address | |
| address_compenents.map { |e| self.send e }.join(" ") | |
| end | |
| def address_changed? | |
| address_compenents.inject(false) { |bool,e| | |
| bool || self.send("#{e}_changed?") | |
| } | |
| end | |
| private | |
| def address_compenents | |
| %w{address_line_1 address_line_2 city state zip_code} | |
| end | |
| end |
address_compenents could be a class variable too since it's static.
I'm trying really hard to prove there's only one me.
Author
Ohhhh, good call on the 'any?'. I had also considered making the address components a constant just to clarify that yes, this is just data storage.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
address_changed? could be reduced to:
You're almost me... :)