Class: ActiveStorageValidations::Matchers::DimensionValidatorMatcher

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

Constant Summary

Constants included from ASVTimeoutable

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) ⇒ DimensionValidatorMatcher

Returns a new instance of DimensionValidatorMatcher.



30
31
32
33
34
35
36
37
38
39
# File 'lib/active_storage_validations/matchers/dimension_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
  @width_min = @width_max = @height_min = @height_max = nil
end

Instance Method Details

#descriptionObject



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

def description
  "validate the image dimensions of :#{@attribute_name}"
end

#failure_messageObject



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

def failure_message
  message = [ "is expected to validate dimensions of :#{@attribute_name}" ]
  build_failure_message(message)
  message.join("\n")
end

#height(height) ⇒ Object



71
72
73
74
# File 'lib/active_storage_validations/matchers/dimension_validator_matcher.rb', line 71

def height(height)
  @height_min = @height_max = height
  self
end

#height_between(range) ⇒ Object



86
87
88
89
# File 'lib/active_storage_validations/matchers/dimension_validator_matcher.rb', line 86

def height_between(range)
  @height_min, @height_max = range.first, range.last
  self
end

#height_max(height) ⇒ Object



81
82
83
84
# File 'lib/active_storage_validations/matchers/dimension_validator_matcher.rb', line 81

def height_max(height)
  @height_max = height
  self
end

#height_min(height) ⇒ Object



76
77
78
79
# File 'lib/active_storage_validations/matchers/dimension_validator_matcher.rb', line 76

def height_min(height)
  @height_min = height
  self
end

#matches?(subject) ⇒ Boolean

Returns:

  • (Boolean)


91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/active_storage_validations/matchers/dimension_validator_matcher.rb', line 91

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? &&
    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



51
52
53
54
# File 'lib/active_storage_validations/matchers/dimension_validator_matcher.rb', line 51

def width(width)
  @width_min = @width_max = width
  self
end

#width_between(range) ⇒ Object



66
67
68
69
# File 'lib/active_storage_validations/matchers/dimension_validator_matcher.rb', line 66

def width_between(range)
  @width_min, @width_max = range.first, range.last
  self
end

#width_max(width) ⇒ Object



61
62
63
64
# File 'lib/active_storage_validations/matchers/dimension_validator_matcher.rb', line 61

def width_max(width)
  @width_max = width
  self
end

#width_min(width) ⇒ Object



56
57
58
59
# File 'lib/active_storage_validations/matchers/dimension_validator_matcher.rb', line 56

def width_min(width)
  @width_min = width
  self
end