Class: ActiveStorageValidations::Matchers::SizeValidatorMatcher
- Inherits:
-
Object
- Object
- ActiveStorageValidations::Matchers::SizeValidatorMatcher
- Defined in:
- lib/active_storage_validations/matchers/size_validator_matcher.rb
Instance Method Summary collapse
- #between(range) ⇒ Object
- #description ⇒ Object
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object
- #greater_than(size) ⇒ Object
- #greater_than_or_equal_to(size) ⇒ Object
-
#initialize(attribute_name) ⇒ SizeValidatorMatcher
constructor
A new instance of SizeValidatorMatcher.
- #less_than(size) ⇒ Object
- #less_than_or_equal_to(size) ⇒ Object
- #matches?(subject) ⇒ Boolean
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 |
#description ⇒ Object
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_message ⇒ Object
51 52 53 |
# File 'lib/active_storage_validations/matchers/size_validator_matcher.rb', line 51 def "is expected to validate file size of #{@attribute_name} to be between #{@low} and #{@high} bytes" end |
#failure_message_when_negated ⇒ Object
55 56 57 |
# File 'lib/active_storage_validations/matchers/size_validator_matcher.rb', line 55 def "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
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 |