Class | Paperclip::Shoulda::Matchers::ValidateAttachmentSizeMatcher
In: | vendor/plugins/paperclip/lib/paperclip/matchers/validate_attachment_size_matcher.rb
Parent: | Object

### Methods

description failure_message greater_than higher_than_high? higher_than_low? in less_than lower_than_high? lower_than_low? matches? negative_failure_message new override_method passes_validation_with_size

### Public Class methods

new(attachment_name)

[Source]

        # File vendor/plugins/paperclip/lib/paperclip/matchers/validate_attachment_size_matcher.rb, line 9
     9:         def initialize attachment_name
    10:           @attachment_name = attachment_name
    11:           @low, @high = 0, (1.0/0)
    12:         end

### Public Instance methods

description()

[Source]

        # File vendor/plugins/paperclip/lib/paperclip/matchers/validate_attachment_size_matcher.rb, line 42
    42:         def description
    43:           "validate the size of attachment #{@attachment_name}"
    44:         end

failure_message()

[Source]

        # File vendor/plugins/paperclip/lib/paperclip/matchers/validate_attachment_size_matcher.rb, line 34
    34:         def failure_message
    35:           "Attachment #{@attachment_name} must be between #{@low} and #{@high} bytes"
    36:         end

greater_than(size)

[Source]

        # File vendor/plugins/paperclip/lib/paperclip/matchers/validate_attachment_size_matcher.rb, line 19
    19:         def greater_than size
    20:           @low = size
    21:           self
    22:         end

in(range)

[Source]

        # File vendor/plugins/paperclip/lib/paperclip/matchers/validate_attachment_size_matcher.rb, line 24
    24:         def in range
    25:           @low, @high = range.first, range.last
    26:           self
    27:         end

less_than(size)

[Source]

        # File vendor/plugins/paperclip/lib/paperclip/matchers/validate_attachment_size_matcher.rb, line 14
    14:         def less_than size
    15:           @high = size
    16:           self
    17:         end

matches?(subject)

[Source]

        # File vendor/plugins/paperclip/lib/paperclip/matchers/validate_attachment_size_matcher.rb, line 29
    29:         def matches? subject
    30:           @subject = subject
    31:           lower_than_low? && higher_than_low? && lower_than_high? && higher_than_high?
    32:         end

negative_failure_message()

[Source]

        # File vendor/plugins/paperclip/lib/paperclip/matchers/validate_attachment_size_matcher.rb, line 38
    38:         def negative_failure_message
    39:           "Attachment #{@attachment_name} cannot be between #{@low} and #{@high} bytes"
    40:         end

### Protected Instance methods

higher_than_high?()

[Source]

        # File vendor/plugins/paperclip/lib/paperclip/matchers/validate_attachment_size_matcher.rb, line 75
    75:         def higher_than_high?
    76:           return true if @high == (1.0/0)
    77:           not passes_validation_with_size(@high + 1)
    78:         end

higher_than_low?()

[Source]

        # File vendor/plugins/paperclip/lib/paperclip/matchers/validate_attachment_size_matcher.rb, line 66
    66:         def higher_than_low?
    67:           passes_validation_with_size(@low + 1)
    68:         end

lower_than_high?()

[Source]

        # File vendor/plugins/paperclip/lib/paperclip/matchers/validate_attachment_size_matcher.rb, line 70
    70:         def lower_than_high?
    71:           return true if @high == (1.0/0)
    72:           passes_validation_with_size(@high - 1)
    73:         end

lower_than_low?()

[Source]

        # File vendor/plugins/paperclip/lib/paperclip/matchers/validate_attachment_size_matcher.rb, line 62
    62:         def lower_than_low?
    63:           not passes_validation_with_size(@low - 1)
    64:         end

override_method(object, method, &replacement)

[Source]

        # File vendor/plugins/paperclip/lib/paperclip/matchers/validate_attachment_size_matcher.rb, line 48
    48:         def override_method object, method, &replacement
    49:           (class << object; self; end).class_eval do
    50:             define_method(method, &replacement)
    51:           end
    52:         end

passes_validation_with_size(new_size)

[Source]

        # File vendor/plugins/paperclip/lib/paperclip/matchers/validate_attachment_size_matcher.rb, line 54
    54:         def passes_validation_with_size(new_size)
    55:           file = StringIO.new(".")
    56:           override_method(file, :size){ new_size }
    57:           attachment = @subject.new.attachment_for(@attachment_name)
    58:           attachment.assign(file)
    59:           attachment.errors[:size].nil?
    60:         end

[Validate]