Class: ActiveStorageValidations::Matchers::AspectRatioValidatorMatcher

Inherits:
Object
  • Object
show all
Includes:
ASVActiveStorageable, ASVAllowBlankable, ASVAttachable, ASVContextable, ASVExceptOnable, ASVMessageable, ASVRspecable, ASVTimeoutable, ASVValidatable
Defined in:
lib/active_storage_validations/matchers/aspect_ratio_validator_matcher.rb

Constant Summary

Constants included from ASVTimeoutable

ActiveStorageValidations::Matchers::ASVTimeoutable::UNSET

Instance Method Summary collapse

Methods included from ASVTimeoutable

#initialize_timeoutable, #timeout

Methods included from ASVRspecable

#failure_message_when_negated, #initialize_rspecable

Methods included from ASVMessageable

#initialize_messageable, #with_message

Methods included from ASVExceptOnable

#except_on, #initialize_except_onable

Methods included from ASVContextable

#initialize_contextable, #on

Methods included from ASVAllowBlankable

#allow_blank, #initialize_allow_blankable

Constructor Details

#initialize(attribute_name) ⇒ AspectRatioValidatorMatcher

Returns a new instance of AspectRatioValidatorMatcher.



30
31
32
33
34
35
36
37
38
39
# File 'lib/active_storage_validations/matchers/aspect_ratio_validator_matcher.rb', line 30

def initialize(attribute_name)
  initialize_allow_blankable
  initialize_contextable
  initialize_except_onable
  initialize_messageable
  initialize_rspecable
  initialize_timeoutable
  @attribute_name = attribute_name
  @allowed_aspect_ratios = @rejected_aspect_ratios = []
end

Instance Method Details

#allowing(*aspect_ratios) ⇒ Object



49
50
51
52
# File 'lib/active_storage_validations/matchers/aspect_ratio_validator_matcher.rb', line 49

def allowing(*aspect_ratios)
  @allowed_aspect_ratios = aspect_ratios.flatten
  self
end

#descriptionObject



41
42
43
# File 'lib/active_storage_validations/matchers/aspect_ratio_validator_matcher.rb', line 41

def description
  "validate the aspect ratios allowed on :#{@attribute_name}."
end

#failure_messageObject



45
46
47
# File 'lib/active_storage_validations/matchers/aspect_ratio_validator_matcher.rb', line 45

def failure_message
  "is expected to validate aspect ratio of :#{@attribute_name}"
end

#matches?(subject) ⇒ Boolean

Returns:

  • (Boolean)


59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/active_storage_validations/matchers/aspect_ratio_validator_matcher.rb', line 59

def matches?(subject)
  @subject = subject.is_a?(Class) ? subject.new : subject

  is_a_valid_active_storage_attribute? &&
    is_context_valid? &&
    is_except_on_valid? &&
    is_allowing_blank? &&
    is_timeout_valid? &&
    is_custom_message_valid? &&
    all_allowed_aspect_ratios_allowed? &&
    all_rejected_aspect_ratios_rejected?
end

#rejecting(*aspect_ratios) ⇒ Object



54
55
56
57
# File 'lib/active_storage_validations/matchers/aspect_ratio_validator_matcher.rb', line 54

def rejecting(*aspect_ratios)
  @rejected_aspect_ratios = aspect_ratios.flatten
  self
end