Created
March 21, 2014 00:37
-
-
Save kerrizor/9677113 to your computer and use it in GitHub Desktop.
This file contains 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
ShippingModel < AR::Base | |
before_validation :validate_address | |
after_save :set_asp_sr_id | |
def initialize(opts) | |
super | |
@validator = opts[:validator] || AddressValidator | |
end | |
private | |
def validate_address | |
@validator.validate_address address | |
end | |
end | |
class AddressValidator | |
def self.validate_address address, validator = UPSValidator.new | |
validator.get_suggestions address | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This type of thing came up for me again where I essentially want to inject in a fake class the an API wrapper that:
How would I blanket inject it in development mode? I understand that it shouldn't have environment-aware stuff in the model (
Rails.env.development?
), but that kind of switch has to go somewhere, right?