Class: ActiveStorageValidations::Matchers::DimensionValidatorMatcher
- Inherits:
-
Object
- Object
- ActiveStorageValidations::Matchers::DimensionValidatorMatcher
- Includes:
- Validatable
- Defined in:
- lib/active_storage_validations/matchers/dimension_validator_matcher.rb
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message ⇒ Object
- #height(height) ⇒ Object
- #height_between(range) ⇒ Object
- #height_max(height) ⇒ Object
- #height_min(height) ⇒ Object
-
#initialize(attribute_name) ⇒ DimensionValidatorMatcher
constructor
A new instance of DimensionValidatorMatcher.
- #matches?(subject) ⇒ Boolean
- #width(width) ⇒ Object
- #width_between(range) ⇒ Object
- #width_max(width) ⇒ Object
- #width_min(width) ⇒ Object
- #with_message(message) ⇒ Object
Constructor Details
#initialize(attribute_name) ⇒ DimensionValidatorMatcher
Returns a new instance of DimensionValidatorMatcher.
14 15 16 17 18 |
# File 'lib/active_storage_validations/matchers/dimension_validator_matcher.rb', line 14 def initialize(attribute_name) @attribute_name = attribute_name @width_min = @width_max = @height_min = @height_max = nil @custom_message = nil end |
Instance Method Details
#description ⇒ Object
20 21 22 |
# File 'lib/active_storage_validations/matchers/dimension_validator_matcher.rb', line 20 def description "validate image dimensions of #{@attribute_name}" end |
#failure_message ⇒ Object
86 87 88 89 90 91 92 |
# File 'lib/active_storage_validations/matchers/dimension_validator_matcher.rb', line 86 def <<~MESSAGE is expected to validate dimensions of #{@attribute_name} width between #{@width_min} and #{@width_max} height between #{@height_min} and #{@height_max} MESSAGE end |
#height(height) ⇒ Object
64 65 66 67 |
# File 'lib/active_storage_validations/matchers/dimension_validator_matcher.rb', line 64 def height(height) @height_min = @height_max = height self end |
#height_between(range) ⇒ Object
59 60 61 62 |
# File 'lib/active_storage_validations/matchers/dimension_validator_matcher.rb', line 59 def height_between(range) @height_min, @height_max = range.first, range.last self end |
#height_max(height) ⇒ Object
49 50 51 52 |
# File 'lib/active_storage_validations/matchers/dimension_validator_matcher.rb', line 49 def height_max(height) @height_max = height self end |
#height_min(height) ⇒ Object
44 45 46 47 |
# File 'lib/active_storage_validations/matchers/dimension_validator_matcher.rb', line 44 def height_min(height) @height_min = height self end |
#matches?(subject) ⇒ Boolean
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/active_storage_validations/matchers/dimension_validator_matcher.rb', line 69 def matches?(subject) @subject = subject.is_a?(Class) ? subject.new : subject responds_to_methods && width_not_smaller_than_min? && width_larger_than_min? && width_smaller_than_max? && width_not_larger_than_max? && width_equals? && height_not_smaller_than_min? && height_larger_than_min? && height_smaller_than_max? && height_not_larger_than_max? && height_equals? && end |
#width(width) ⇒ Object
39 40 41 42 |
# File 'lib/active_storage_validations/matchers/dimension_validator_matcher.rb', line 39 def width(width) @width_min = @width_max = width self end |
#width_between(range) ⇒ Object
54 55 56 57 |
# File 'lib/active_storage_validations/matchers/dimension_validator_matcher.rb', line 54 def width_between(range) @width_min, @width_max = range.first, range.last self end |
#width_max(width) ⇒ Object
29 30 31 32 |
# File 'lib/active_storage_validations/matchers/dimension_validator_matcher.rb', line 29 def width_max(width) @width_max = width self end |
#width_min(width) ⇒ Object
24 25 26 27 |
# File 'lib/active_storage_validations/matchers/dimension_validator_matcher.rb', line 24 def width_min(width) @width_min = width self end |
#with_message(message) ⇒ Object
34 35 36 37 |
# File 'lib/active_storage_validations/matchers/dimension_validator_matcher.rb', line 34 def () @custom_message = self end |