Class: Paperclip::Shoulda::Matchers::ValidateAttachmentSizeMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/paperclip/matchers/validate_attachment_size_matcher.rb

Instance Method Summary (collapse)

Constructor Details

- (ValidateAttachmentSizeMatcher) initialize(attachment_name)

Returns a new instance of ValidateAttachmentSizeMatcher



19
20
21
# File 'lib/paperclip/matchers/validate_attachment_size_matcher.rb', line 19

def initialize attachment_name
  @attachment_name = attachment_name
end

Instance Method Details

- (Object) description



53
54
55
# File 'lib/paperclip/matchers/validate_attachment_size_matcher.rb', line 53

def description
  "validate the size of attachment #{@attachment_name}"
end

- (Object) failure_message



44
45
46
# File 'lib/paperclip/matchers/validate_attachment_size_matcher.rb', line 44

def failure_message
  "Attachment #{@attachment_name} must be between #{@low} and #{@high} bytes"
end

- (Object) failure_message_when_negated Also known as: negative_failure_message



48
49
50
# File 'lib/paperclip/matchers/validate_attachment_size_matcher.rb', line 48

def failure_message_when_negated
  "Attachment #{@attachment_name} cannot be between #{@low} and #{@high} bytes"
end

- (Object) greater_than(size)



28
29
30
31
# File 'lib/paperclip/matchers/validate_attachment_size_matcher.rb', line 28

def greater_than size
  @low = size
  self
end

- (Object) in(range)



33
34
35
36
# File 'lib/paperclip/matchers/validate_attachment_size_matcher.rb', line 33

def in range
  @low, @high = range.first, range.last
  self
end

- (Object) less_than(size)



23
24
25
26
# File 'lib/paperclip/matchers/validate_attachment_size_matcher.rb', line 23

def less_than size
  @high = size
  self
end

- (Boolean) matches?(subject)

Returns:

  • (Boolean)


38
39
40
41
42
# File 'lib/paperclip/matchers/validate_attachment_size_matcher.rb', line 38

def matches? subject
  @subject = subject
  @subject = @subject.new if @subject.class == Class
  lower_than_low? && higher_than_low? && lower_than_high? && higher_than_high?
end