Class: SlugValidator::GovernmentPageValidator
Instance Method Summary
collapse
#ends_with?, #of_kind?, #starts_with?, #url_after_first_slash, #url_after_first_slash_is_valid_slug!, #valid_slug?
Instance Method Details
#applicable? ⇒ Boolean
102
103
104
|
# File 'app/validators/slug_validator.rb', line 102
def applicable?
record.respond_to?(:kind) && prefixed_whitehall_format_names.include?(record.kind)
end
|
#url_parts ⇒ Object
97
98
99
100
|
# File 'app/validators/slug_validator.rb', line 97
def url_parts
super.map {|part| part.gsub(/\./, '') }
end
|
#validate! ⇒ Object
106
107
108
109
110
111
|
# File 'app/validators/slug_validator.rb', line 106
def validate!
record.errors[attribute] << "Inside Government slugs must have a government/ prefix" unless starts_with?('government/')
unless url_parts.all? { |url_part| valid_slug?(url_part) }
record.errors[attribute] << "must be usable in a URL"
end
end
|