Class: ActiveStorageValidations::Matchers::SizeValidatorMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/active_storage_validations/matchers/size_validator_matcher.rb

Instance Method Summary collapse

Constructor Details

#initialize(attribute_name) ⇒ SizeValidatorMatcher

Returns a new instance of SizeValidatorMatcher.



12
13
14
15
# File 'lib/active_storage_validations/matchers/size_validator_matcher.rb', line 12

def initialize(attribute_name)
  @attribute_name = attribute_name
  @low = @high = nil
end

Instance Method Details

#between(range) ⇒ Object



41
42
43
44
# File 'lib/active_storage_validations/matchers/size_validator_matcher.rb', line 41

def between(range)
  @low, @high = range.first, range.last
  self
end

#descriptionObject



17
18
19
# File 'lib/active_storage_validations/matchers/size_validator_matcher.rb', line 17

def description
  "validate file size of #{@attribute_name}"
end

#failure_messageObject



51
52
53
# File 'lib/active_storage_validations/matchers/size_validator_matcher.rb', line 51

def failure_message
  "is expected to validate file size of #{@attribute_name} to be between #{@low} and #{@high} bytes"
end

#failure_message_when_negatedObject



55
56
57
# File 'lib/active_storage_validations/matchers/size_validator_matcher.rb', line 55

def failure_message_when_negated
  "is expected to not validate file size of #{@attribute_name} to be between #{@low} and #{@high} bytes"
end

#greater_than(size) ⇒ Object



31
32
33
34
# File 'lib/active_storage_validations/matchers/size_validator_matcher.rb', line 31

def greater_than(size)
  @low = size + 1.byte
  self
end

#greater_than_or_equal_to(size) ⇒ Object



36
37
38
39
# File 'lib/active_storage_validations/matchers/size_validator_matcher.rb', line 36

def greater_than_or_equal_to(size)
  @low = size
  self
end

#less_than(size) ⇒ Object



21
22
23
24
# File 'lib/active_storage_validations/matchers/size_validator_matcher.rb', line 21

def less_than(size)
  @high = size - 1.byte
  self
end

#less_than_or_equal_to(size) ⇒ Object



26
27
28
29
# File 'lib/active_storage_validations/matchers/size_validator_matcher.rb', line 26

def less_than_or_equal_to(size)
  @high = size
  self
end

#matches?(subject) ⇒ Boolean

Returns:

  • (Boolean)


46
47
48
49
# File 'lib/active_storage_validations/matchers/size_validator_matcher.rb', line 46

def matches?(subject)
  @subject = subject.is_a?(Class) ? subject.new : subject
  responds_to_methods && lower_than_low? && higher_than_low? && lower_than_high? && higher_than_high?
end