Class: Spree::Address::StateValidator

Inherits:
Object
  • Object
show all
Defined in:
app/models/spree/address/state_validator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(address) ⇒ StateValidator

Returns a new instance of StateValidator.



8
9
10
# File 'app/models/spree/address/state_validator.rb', line 8

def initialize(address)
  @address = address
end

Instance Attribute Details

#addressObject (readonly)

Returns the value of attribute address.



5
6
7
# File 'app/models/spree/address/state_validator.rb', line 5

def address
  @address
end

Instance Method Details

#performObject



12
13
14
15
16
17
18
19
20
21
22
# File 'app/models/spree/address/state_validator.rb', line 12

def perform
  return unless state_required?

  if country.present?
    normalize_state if state.present?
    normalize_state_name if state_name.present?
  end

  validate_not_blank
  validate_matches_country
end