Class: ActiveStorageValidations::Matchers::AspectRatioValidatorMatcher

Inherits:
Object
  • Object
show all
Includes:
ActiveStorageable, AllowBlankable, Contextable, Messageable, Rspecable, Validatable
Defined in:
lib/active_storage_validations/matchers/aspect_ratio_validator_matcher.rb

Instance Method Summary collapse

Methods included from Rspecable

#failure_message_when_negated, #initialize_rspecable

Methods included from Messageable

#initialize_messageable, #with_message

Methods included from Contextable

#initialize_contextable, #on

Methods included from AllowBlankable

#allow_blank, #initialize_allow_blankable

Constructor Details

#initialize(attribute_name) ⇒ AspectRatioValidatorMatcher

Returns a new instance of AspectRatioValidatorMatcher.



24
25
26
27
28
29
30
31
# File 'lib/active_storage_validations/matchers/aspect_ratio_validator_matcher.rb', line 24

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

Instance Method Details

#allowing(*aspect_ratios) ⇒ Object



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

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

#descriptionObject



33
34
35
# File 'lib/active_storage_validations/matchers/aspect_ratio_validator_matcher.rb', line 33

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

#failure_messageObject



37
38
39
# File 'lib/active_storage_validations/matchers/aspect_ratio_validator_matcher.rb', line 37

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

#matches?(subject) ⇒ Boolean

Returns:

  • (Boolean)


51
52
53
54
55
56
57
58
59
60
# File 'lib/active_storage_validations/matchers/aspect_ratio_validator_matcher.rb', line 51

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

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

#rejecting(*aspect_ratios) ⇒ Object



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

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