Class: Paperclip::Shoulda::Matchers::ValidateAttachmentSizeMatcher
- Inherits:
-
Object
- Object
- Paperclip::Shoulda::Matchers::ValidateAttachmentSizeMatcher
- Defined in:
- lib/paperclip/matchers/validate_attachment_size_matcher.rb
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message ⇒ Object
- #greater_than(size) ⇒ Object
- #in(range) ⇒ Object
-
#initialize(attachment_name) ⇒ ValidateAttachmentSizeMatcher
constructor
A new instance of ValidateAttachmentSizeMatcher.
- #less_than(size) ⇒ Object
- #matches?(subject) ⇒ Boolean
- #negative_failure_message ⇒ Object
Constructor Details
#initialize(attachment_name) ⇒ ValidateAttachmentSizeMatcher
Returns a new instance of ValidateAttachmentSizeMatcher.
9 10 11 12 |
# File 'lib/paperclip/matchers/validate_attachment_size_matcher.rb', line 9 def initialize @attachment_name = @low, @high = 0, (1.0/0) end |
Instance Method Details
#description ⇒ Object
42 43 44 |
# File 'lib/paperclip/matchers/validate_attachment_size_matcher.rb', line 42 def description "validate the size of attachment #{@attachment_name}" end |
#failure_message ⇒ Object
34 35 36 |
# File 'lib/paperclip/matchers/validate_attachment_size_matcher.rb', line 34 def "Attachment #{@attachment_name} must be between #{@low} and #{@high} bytes" end |
#greater_than(size) ⇒ Object
19 20 21 22 |
# File 'lib/paperclip/matchers/validate_attachment_size_matcher.rb', line 19 def greater_than size @low = size self end |
#in(range) ⇒ Object
24 25 26 27 |
# File 'lib/paperclip/matchers/validate_attachment_size_matcher.rb', line 24 def in range @low, @high = range.first, range.last self end |
#less_than(size) ⇒ Object
14 15 16 17 |
# File 'lib/paperclip/matchers/validate_attachment_size_matcher.rb', line 14 def less_than size @high = size self end |
#matches?(subject) ⇒ Boolean
29 30 31 32 |
# File 'lib/paperclip/matchers/validate_attachment_size_matcher.rb', line 29 def matches? subject @subject = subject lower_than_low? && higher_than_low? && lower_than_high? && higher_than_high? end |
#negative_failure_message ⇒ Object
38 39 40 |
# File 'lib/paperclip/matchers/validate_attachment_size_matcher.rb', line 38 def "Attachment #{@attachment_name} cannot be between #{@low} and #{@high} bytes" end |