Class: MiniDefender::Rules::CountryCode
Constant Summary
collapse
- COUNTRIES =
ISO3166::Country.pluck(:alpha2).flatten
Class Method Summary
collapse
Instance Method Summary
collapse
#active?, available?, #bails?, #default_value, #defaults?, #error_message, #excluded?, #force_coerce?, #implicit?, make, #priority, #stops?, #with_message
Class Method Details
.signature ⇒ Object
8
9
10
|
# File 'lib/mini_defender/rules/country_code.rb', line 8
def self.signature
'country_code'
end
|
Instance Method Details
#coerce(value) ⇒ Object
12
13
14
|
# File 'lib/mini_defender/rules/country_code.rb', line 12
def coerce(value)
value.strip.upcase
end
|
#message(attribute, value, validator) ⇒ Object
20
21
22
|
# File 'lib/mini_defender/rules/country_code.rb', line 20
def message(attribute, value, validator)
'The value must be a valid ISO3166 country code.'
end
|
#passes?(attribute, value, validator) ⇒ Boolean
16
17
18
|
# File 'lib/mini_defender/rules/country_code.rb', line 16
def passes?(attribute, value, validator)
value.is_a?(String) && COUNTRIES.include?(value.strip.upcase)
end
|