Module: Auspost::Postie::ActiveRecord::Validations
- Included in:
- ClassMethods
- Defined in:
- lib/auspost/active_record/validations.rb
Defined Under Namespace
Modules: ClassMethods
Constant Summary collapse
- @@valid_attributes =
{ :state => {:accessor => :state, :message => ["%s is not found in the %s postcode", :state, :postcode] }, :postcode => {:accessor => :postcode, :message => ["%s cannot be found", :postcode] }, :suburb => {:accessor => :suburb, :message => ["%s is not found in the %s postcode", :suburb, :postcode] }, }
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.included(base) ⇒ Object
13 14 15 |
# File 'lib/auspost/active_record/validations.rb', line 13 def self.included(base) base.extend ClassMethods end |
Instance Method Details
#valid_attributes ⇒ Object
40 41 42 |
# File 'lib/auspost/active_record/validations.rb', line 40 def valid_attributes @@valid_attributes end |
#validate_location ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/auspost/active_record/validations.rb', line 18 def validate_location result = location?(map_attributes) if result && !result.status result.errors.each do |error| = @@valid_attributes[error.accessor][:message] if .is_a?(String) errors.add(error.accessor, ) else mappings = [1..-1].map do |x| if x.to_s.include?(".") methods = x.split(".") send(methods.first).send(methods.last).to_s.upcase else send(x).to_s.upcase end end errors.add(error.accessor, .first % mappings) end end end end |