Class: SlugValidator::InstanceValidator
- Inherits:
-
Struct
- Object
- Struct
- SlugValidator::InstanceValidator
show all
- Defined in:
- app/validators/slug_validator.rb
Instance Method Summary
collapse
Instance Method Details
#ends_with?(expected_suffix) ⇒ Boolean
24
25
26
|
# File 'app/validators/slug_validator.rb', line 24
def ends_with?(expected_suffix)
value.to_s.end_with?(expected_suffix)
end
|
#of_kind?(expected_kind) ⇒ Boolean
28
29
30
|
# File 'app/validators/slug_validator.rb', line 28
def of_kind?(expected_kind)
record.respond_to?(:kind) && [*expected_kind].include?(record.kind)
end
|
#starts_with?(expected_prefix) ⇒ Boolean
20
21
22
|
# File 'app/validators/slug_validator.rb', line 20
def starts_with?(expected_prefix)
value.to_s.start_with?(expected_prefix)
end
|
#url_after_first_slash ⇒ Object
32
33
34
|
# File 'app/validators/slug_validator.rb', line 32
def url_after_first_slash
value.to_s.split('/', 2)[1]
end
|
#url_after_first_slash_is_valid_slug! ⇒ Object
36
37
38
39
40
|
# File 'app/validators/slug_validator.rb', line 36
def url_after_first_slash_is_valid_slug!
if !valid_slug?(url_after_first_slash)
record.errors[attribute] << "must be usable in a url"
end
end
|
#url_parts ⇒ Object
42
43
44
|
# File 'app/validators/slug_validator.rb', line 42
def url_parts
value.to_s.split("/")
end
|
#valid_slug?(url_part) ⇒ Boolean
46
47
48
49
50
51
|
# File 'app/validators/slug_validator.rb', line 46
def valid_slug?(url_part)
! url_part.to_s.match(/[^a-z0-9\-_]/)
end
|