Class: Paperclip::Shoulda::Matchers::ValidateAttachmentContentTypeMatcher
- Inherits:
-
Object
- Object
- Paperclip::Shoulda::Matchers::ValidateAttachmentContentTypeMatcher
- Defined in:
- lib/paperclip/matchers/validate_attachment_content_type_matcher.rb
Instance Method Summary collapse
- #allowing(*types) ⇒ Object
- #description ⇒ Object
- #failure_message ⇒ Object
-
#initialize(attachment_name) ⇒ ValidateAttachmentContentTypeMatcher
constructor
A new instance of ValidateAttachmentContentTypeMatcher.
- #matches?(subject) ⇒ Boolean
- #negative_failure_message ⇒ Object
- #rejecting(*types) ⇒ Object
Constructor Details
#initialize(attachment_name) ⇒ ValidateAttachmentContentTypeMatcher
Returns a new instance of ValidateAttachmentContentTypeMatcher.
18 19 20 21 22 |
# File 'lib/paperclip/matchers/validate_attachment_content_type_matcher.rb', line 18 def initialize @attachment_name = @allowed_types = [] @rejected_types = [] end |
Instance Method Details
#allowing(*types) ⇒ Object
24 25 26 27 |
# File 'lib/paperclip/matchers/validate_attachment_content_type_matcher.rb', line 24 def allowing *types @allowed_types = types.flatten self end |
#description ⇒ Object
57 58 59 |
# File 'lib/paperclip/matchers/validate_attachment_content_type_matcher.rb', line 57 def description "validate the content types allowed on attachment #{@attachment_name}" end |
#failure_message ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/paperclip/matchers/validate_attachment_content_type_matcher.rb', line 41 def "".tap do |str| str << "Content types #{@allowed_types.join(", ")} should be accepted" if @allowed_types.present? str << "\n" if @allowed_types.present? && @rejected_types.present? str << "Content types #{@rejected_types.join(", ")} should be rejected by #{@attachment_name}" if @rejected_types.present? end end |
#matches?(subject) ⇒ Boolean
34 35 36 37 38 39 |
# File 'lib/paperclip/matchers/validate_attachment_content_type_matcher.rb', line 34 def matches? subject @subject = subject @subject = @subject.class unless Class === @subject @allowed_types && @rejected_types && allowed_types_allowed? && rejected_types_rejected? end |
#negative_failure_message ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/paperclip/matchers/validate_attachment_content_type_matcher.rb', line 49 def "".tap do |str| str << "Content types #{@allowed_types.join(", ")} should be rejected" if @allowed_types.present? str << "\n" if @allowed_types.present? && @rejected_types.present? str << "Content types #{@rejected_types.join(", ")} should be accepted by #{@attachment_name}" if @rejected_types.present? end end |
#rejecting(*types) ⇒ Object
29 30 31 32 |
# File 'lib/paperclip/matchers/validate_attachment_content_type_matcher.rb', line 29 def rejecting *types @rejected_types = types.flatten self end |