Class: ActiveStorageValidations::Matchers::DimensionValidatorMatcher

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

Instance Method Summary collapse

Methods included from ASVRspecable

#failure_message_when_negated, #initialize_rspecable

Methods included from ASVMessageable

#initialize_messageable, #with_message

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.



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

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



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

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

#failure_messageObject



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

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

#height(height) ⇒ Object



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

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

#height_between(range) ⇒ Object



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

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

#height_max(height) ⇒ Object



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

def height_max(height)
  @height_max = height
  self
end

#height_min(height) ⇒ Object



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

def height_min(height)
  @height_min = height
  self
end

#matches?(subject) ⇒ Boolean

Returns:

  • (Boolean)


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

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



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

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

#width_between(range) ⇒ Object



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

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

#width_max(width) ⇒ Object



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

def width_max(width)
  @width_max = width
  self
end

#width_min(width) ⇒ Object



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

def width_min(width)
  @width_min = width
  self
end