Module: RailsGallery::PhotoValidation
- Included in:
- ViewHelper
- Defined in:
- lib/rails-gallery/photo_validation.rb
Instance Method Summary collapse
Instance Method Details
#validate_gallery_photo(photo) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/rails-gallery/photo_validation.rb', line 3 def validate_gallery_photo photo return "Photo must be a kind of RGallery::Photo, was: #{photo}" unless photo.kind_of?(RGallery::Photo) return 'Photo must have a #path method' unless photo.respond_to? :path return 'Photo must have a #title method' unless photo.respond_to? :title begin photo.filename photo.file_path rescue Exception => e return "filename or file_path could not be resolved for: #{photo}, cause: #{e}" end return "Photo must have a path: #{photo}" if photo.path.blank? return "Photo must have a title: #{photo}" if photo.title.blank? true end |
#validate_gallery_photo!(photo) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/rails-gallery/photo_validation.rb', line 20 def validate_gallery_photo! photo raise ArgumentError, "Photo must be a kind of RGallery::Photo, was: #{photo}" unless photo.kind_of?(RGallery::Photo) raise ArgumentError, 'Photo must have a #path method' unless photo.respond_to? :path raise ArgumentError, 'Photo must have a #title method' unless photo.respond_to? :title begin photo.filename photo.file_path rescue Exception => e raise ::RailsGallery::ConfigurationError, "filename or file_path could not be resolved for: #{photo}, cause: #{e}" end raise ArgumentError, "Photo must have a path: #{photo}" if photo.path.blank? raise ArgumentError, "Photo must have a title: #{photo}" if photo.title.blank? true end |