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
22
23
24
|
# File 'app/validators/slug_validator.rb', line 22
def ends_with?(expected_suffix)
value.to_s.end_with?(expected_suffix)
end
|
#of_kind?(expected_kind) ⇒ Boolean
26
27
28
|
# File 'app/validators/slug_validator.rb', line 26
def of_kind?(expected_kind)
record.respond_to?(:kind) && [*expected_kind].include?(record.kind)
end
|
#starts_with?(expected_prefix) ⇒ Boolean
18
19
20
|
# File 'app/validators/slug_validator.rb', line 18
def starts_with?(expected_prefix)
value.to_s.start_with?(expected_prefix)
end
|
#url_after_first_slash ⇒ Object
30
31
32
|
# File 'app/validators/slug_validator.rb', line 30
def url_after_first_slash
value.to_s.split('/', 2)[1]
end
|
#url_after_first_slash_is_valid_slug! ⇒ Object
34
35
36
37
38
|
# File 'app/validators/slug_validator.rb', line 34
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
40
41
42
|
# File 'app/validators/slug_validator.rb', line 40
def url_parts
value.to_s.split("/")
end
|
#valid_slug?(url_part) ⇒ Boolean
44
45
46
47
48
49
|
# File 'app/validators/slug_validator.rb', line 44
def valid_slug?(url_part)
! url_part.to_s.match(/[^a-z0-9\-_]/)
end
|