Class: ActiveStorageValidations::Matchers::DimensionValidatorMatcher
- Inherits:
-
Object
- Object
- ActiveStorageValidations::Matchers::DimensionValidatorMatcher
- 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.
10 11 12 13 14 |
# File 'lib/active_storage_validations/matchers/dimension_validator_matcher.rb', line 10 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
16 17 18 |
# File 'lib/active_storage_validations/matchers/dimension_validator_matcher.rb', line 16 def description "validate image dimensions of #{@attribute_name}" end |
#failure_message ⇒ Object
72 73 74 75 76 77 78 |
# File 'lib/active_storage_validations/matchers/dimension_validator_matcher.rb', line 72 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
60 61 62 63 |
# File 'lib/active_storage_validations/matchers/dimension_validator_matcher.rb', line 60 def height(height) @height_min = @height_max = height self end |
#height_between(range) ⇒ Object
55 56 57 58 |
# File 'lib/active_storage_validations/matchers/dimension_validator_matcher.rb', line 55 def height_between(range) @height_min, @height_max = range.first, range.last self end |
#height_max(height) ⇒ Object
45 46 47 48 |
# File 'lib/active_storage_validations/matchers/dimension_validator_matcher.rb', line 45 def height_max(height) @height_max = height self end |
#height_min(height) ⇒ Object
40 41 42 43 |
# File 'lib/active_storage_validations/matchers/dimension_validator_matcher.rb', line 40 def height_min(height) @height_min = height self end |
#matches?(subject) ⇒ Boolean
65 66 67 68 69 70 |
# File 'lib/active_storage_validations/matchers/dimension_validator_matcher.rb', line 65 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
35 36 37 38 |
# File 'lib/active_storage_validations/matchers/dimension_validator_matcher.rb', line 35 def width(width) @width_min = @width_max = width self end |
#width_between(range) ⇒ Object
50 51 52 53 |
# File 'lib/active_storage_validations/matchers/dimension_validator_matcher.rb', line 50 def width_between(range) @width_min, @width_max = range.first, range.last self end |
#width_max(width) ⇒ Object
25 26 27 28 |
# File 'lib/active_storage_validations/matchers/dimension_validator_matcher.rb', line 25 def width_max(width) @width_max = width self end |
#width_min(width) ⇒ Object
20 21 22 23 |
# File 'lib/active_storage_validations/matchers/dimension_validator_matcher.rb', line 20 def width_min(width) @width_min = width self end |
#with_message(message) ⇒ Object
30 31 32 33 |
# File 'lib/active_storage_validations/matchers/dimension_validator_matcher.rb', line 30 def () @custom_message = self end |