Class: ActiveStorageValidations::Matchers::RatioValidatorMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/lupca/carrierwave_image_ratio_validation/matchers/#ratio_validator_matcher.rb

Instance Method Summary collapse

Constructor Details

#initialize(attribute_name) ⇒ RatioValidatorMatcher

Returns a new instance of RatioValidatorMatcher.



12
13
14
15
# File 'lib/lupca/carrierwave_image_ratio_validation/matchers/#ratio_validator_matcher.rb', line 12

def initialize(attribute_name)
  @attribute_name = attribute_name
  @ratio_range = nil
end

Instance Method Details

#descriptionObject



17
18
19
# File 'lib/lupca/carrierwave_image_ratio_validation/matchers/#ratio_validator_matcher.rb', line 17

def description
  "validate image ratio of #{@attribute_name}"
end

#failure_messageObject



31
32
33
# File 'lib/lupca/carrierwave_image_ratio_validation/matchers/#ratio_validator_matcher.rb', line 31

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

#failure_message_when_negatedObject



35
36
37
# File 'lib/lupca/carrierwave_image_ratio_validation/matchers/#ratio_validator_matcher.rb', line 35

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

#is_ratio_in(range_ratio) ⇒ Object



21
22
23
24
# File 'lib/lupca/carrierwave_image_ratio_validation/matchers/#ratio_validator_matcher.rb', line 21

def is_ratio_in range_ratio
  @range_ratio = range_ratio
  self
end

#matches?(subject) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
29
# File 'lib/lupca/carrierwave_image_ratio_validation/matchers/#ratio_validator_matcher.rb', line 26

def matches?(subject)
  @subject = subject.is_a?(Class) ? subject.new : subject
  responds_to_methods && valid_ratio?
end