Class: ActiveStorageValidations::Matchers::AspectRatioValidatorMatcher

Inherits:
Object
  • Object
show all
Includes:
ActiveStorageable, AllowBlankable, Attachable, 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.



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

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



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

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

#descriptionObject



35
36
37
# File 'lib/active_storage_validations/matchers/aspect_ratio_validator_matcher.rb', line 35

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

#failure_messageObject



39
40
41
# File 'lib/active_storage_validations/matchers/aspect_ratio_validator_matcher.rb', line 39

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

#matches?(subject) ⇒ Boolean

Returns:

  • (Boolean)


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

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



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

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