Class: ActiveStorageValidations::Matchers::DimensionValidatorMatcher

Inherits:
Object
  • Object
show all
Includes:
ActiveStorageable, AllowBlankable, Contextable, Messageable, Rspecable, Validatable
Defined in:
lib/active_storage_validations/matchers/dimension_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) ⇒ DimensionValidatorMatcher

Returns a new instance of DimensionValidatorMatcher.



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

def initialize(attribute_name)
  initialize_allow_blankable
  initialize_contextable
  initialize_messageable
  initialize_rspecable
  @attribute_name = attribute_name
  @width_min = @width_max = @height_min = @height_max = nil
end

Instance Method Details

#descriptionObject



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

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

#failure_messageObject



37
38
39
40
41
# File 'lib/active_storage_validations/matchers/dimension_validator_matcher.rb', line 37

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

#height(height) ⇒ Object



63
64
65
66
# File 'lib/active_storage_validations/matchers/dimension_validator_matcher.rb', line 63

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

#height_between(range) ⇒ Object



78
79
80
81
# File 'lib/active_storage_validations/matchers/dimension_validator_matcher.rb', line 78

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

#height_max(height) ⇒ Object



73
74
75
76
# File 'lib/active_storage_validations/matchers/dimension_validator_matcher.rb', line 73

def height_max(height)
  @height_max = height
  self
end

#height_min(height) ⇒ Object



68
69
70
71
# File 'lib/active_storage_validations/matchers/dimension_validator_matcher.rb', line 68

def height_min(height)
  @height_min = height
  self
end

#matches?(subject) ⇒ Boolean

Returns:

  • (Boolean)


83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/active_storage_validations/matchers/dimension_validator_matcher.rb', line 83

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



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

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

#width_between(range) ⇒ Object



58
59
60
61
# File 'lib/active_storage_validations/matchers/dimension_validator_matcher.rb', line 58

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

#width_max(width) ⇒ Object



53
54
55
56
# File 'lib/active_storage_validations/matchers/dimension_validator_matcher.rb', line 53

def width_max(width)
  @width_max = width
  self
end

#width_min(width) ⇒ Object



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

def width_min(width)
  @width_min = width
  self
end