Class: ValidationHelperCollection
- Inherits:
-
Object
- Object
- ValidationHelperCollection
- Defined in:
- lib/fae/validation_helper_collection.rb
Instance Method Summary collapse
- #email ⇒ Object
- #email_regex ⇒ Object
-
#slug ⇒ Object
Complete Hash Validations.
- #slug_regex ⇒ Object
- #url ⇒ Object
- #url_regex ⇒ Object
- #youtube_regex ⇒ Object
- #youtube_url ⇒ Object
- #zip ⇒ Object
- #zip_regex ⇒ Object
Instance Method Details
#email ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/fae/validation_helper_collection.rb', line 36 def email { allow_blank: true, format: { with: self.email_regex, message: 'is invalid' } } end |
#email_regex ⇒ Object
7 8 9 |
# File 'lib/fae/validation_helper_collection.rb', line 7 def email_regex /\A\s*(([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})[\s\/,;]*)+\z/ end |
#slug ⇒ Object
Complete Hash Validations
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/fae/validation_helper_collection.rb', line 25 def slug { uniqueness: true, presence: true, format: { with: self.slug_regex, message: 'cannot have spaces or special characters' } } end |
#slug_regex ⇒ Object
3 4 5 |
# File 'lib/fae/validation_helper_collection.rb', line 3 def slug_regex /\A[-_a-zA-Z0-9]+\z/ end |
#url ⇒ Object
46 47 48 49 50 51 52 53 54 |
# File 'lib/fae/validation_helper_collection.rb', line 46 def url { allow_blank: true, format: { with: self.url_regex, message: 'is invalid' } } end |
#url_regex ⇒ Object
11 12 13 |
# File 'lib/fae/validation_helper_collection.rb', line 11 def url_regex /\A(https?:\/\/)/ end |
#youtube_regex ⇒ Object
19 20 21 |
# File 'lib/fae/validation_helper_collection.rb', line 19 def youtube_regex /[a-zA-Z0-9_-]{11}/ end |
#youtube_url ⇒ Object
66 67 68 69 70 71 72 73 74 |
# File 'lib/fae/validation_helper_collection.rb', line 66 def youtube_url { allow_blank: true, format: { with: self.youtube_regex, message: 'is invalid' } } end |
#zip ⇒ Object
56 57 58 59 60 61 62 63 64 |
# File 'lib/fae/validation_helper_collection.rb', line 56 def zip { allow_blank: true, format: { with: self.zip_regex, message: 'is invalid' } } end |
#zip_regex ⇒ Object
15 16 17 |
# File 'lib/fae/validation_helper_collection.rb', line 15 def zip_regex /\A(\d{5})?\z/ end |