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
- #with_message(message) ⇒ Object
Constructor Details
#initialize(attribute_name) ⇒ SizeValidatorMatcher
Returns a new instance of SizeValidatorMatcher.
12 13 14 15 16 |
# File 'lib/active_storage_validations/matchers/size_validator_matcher.rb', line 12 def initialize(attribute_name) @attribute_name = attribute_name @min = @max = nil @custom_message = nil end |
Instance Method Details
#between(range) ⇒ Object
42 43 44 45 |
# File 'lib/active_storage_validations/matchers/size_validator_matcher.rb', line 42 def between(range) @min, @max = range.first, range.last self end |
#description ⇒ Object
18 19 20 |
# File 'lib/active_storage_validations/matchers/size_validator_matcher.rb', line 18 def description "validate file size of #{@attribute_name}" end |
#failure_message ⇒ Object
57 58 59 |
# File 'lib/active_storage_validations/matchers/size_validator_matcher.rb', line 57 def "is expected to validate file size of #{@attribute_name} to be between #{@min} and #{@max} bytes" end |
#failure_message_when_negated ⇒ Object
61 62 63 |
# File 'lib/active_storage_validations/matchers/size_validator_matcher.rb', line 61 def "is expected to not validate file size of #{@attribute_name} to be between #{@min} and #{@max} bytes" end |
#greater_than(size) ⇒ Object
32 33 34 35 |
# File 'lib/active_storage_validations/matchers/size_validator_matcher.rb', line 32 def greater_than(size) @min = size + 1.byte self end |
#greater_than_or_equal_to(size) ⇒ Object
37 38 39 40 |
# File 'lib/active_storage_validations/matchers/size_validator_matcher.rb', line 37 def greater_than_or_equal_to(size) @min = size self end |
#less_than(size) ⇒ Object
22 23 24 25 |
# File 'lib/active_storage_validations/matchers/size_validator_matcher.rb', line 22 def less_than(size) @max = size - 1.byte self end |
#less_than_or_equal_to(size) ⇒ Object
27 28 29 30 |
# File 'lib/active_storage_validations/matchers/size_validator_matcher.rb', line 27 def less_than_or_equal_to(size) @max = size self end |
#matches?(subject) ⇒ Boolean
52 53 54 55 |
# File 'lib/active_storage_validations/matchers/size_validator_matcher.rb', line 52 def matches?(subject) @subject = subject.is_a?(Class) ? subject.new : subject responds_to_methods && not_lower_than_min? && higher_than_min? && lower_than_max? && not_higher_than_max? end |
#with_message(message) ⇒ Object
47 48 49 50 |
# File 'lib/active_storage_validations/matchers/size_validator_matcher.rb', line 47 def () @custom_message = self end |