Class: SlugValidator::GovernmentPageValidator

Inherits:
InstanceValidator show all
Defined in:
app/validators/slug_validator.rb

Instance Method Summary collapse

Methods inherited from InstanceValidator

#ends_with?, #of_kind?, #starts_with?, #url_after_first_slash, #url_after_first_slash_is_valid_slug!, #valid_slug?

Instance Method Details

#applicable?Boolean

Returns:

  • (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_partsObject



97
98
99
100
# File 'app/validators/slug_validator.rb', line 97

def url_parts
  # Some inside govt slugs have a . in them (eg news articles with no english translation)
  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