Class: ActiveStorageValidations::Matchers::BaseComparisonValidatorMatcher

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

Instance Method Summary collapse

Methods included from ASVRspecable

#description, #failure_message, #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) ⇒ BaseComparisonValidatorMatcher

Returns a new instance of BaseComparisonValidatorMatcher.



29
30
31
32
33
34
35
36
37
# File 'lib/active_storage_validations/matchers/base_comparison_validator_matcher.rb', line 29

def initialize(attribute_name)
  initialize_allow_blankable
  initialize_contextable
  initialize_except_onable
  initialize_messageable
  initialize_rspecable
  @attribute_name = attribute_name
  @min = @max = nil
end

Instance Method Details

#between(range) ⇒ Object



59
60
61
62
# File 'lib/active_storage_validations/matchers/base_comparison_validator_matcher.rb', line 59

def between(range)
  @min, @max = range.first, range.last
  self
end

#equal_to(value) ⇒ Object



64
65
66
67
# File 'lib/active_storage_validations/matchers/base_comparison_validator_matcher.rb', line 64

def equal_to(value)
  @exact = value
  self
end

#greater_than(value) ⇒ Object



49
50
51
52
# File 'lib/active_storage_validations/matchers/base_comparison_validator_matcher.rb', line 49

def greater_than(value)
  @min = value + smallest_measurement
  self
end

#greater_than_or_equal_to(value) ⇒ Object



54
55
56
57
# File 'lib/active_storage_validations/matchers/base_comparison_validator_matcher.rb', line 54

def greater_than_or_equal_to(value)
  @min = value
  self
end

#less_than(value) ⇒ Object



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

def less_than(value)
  @max = value - smallest_measurement
  self
end

#less_than_or_equal_to(value) ⇒ Object



44
45
46
47
# File 'lib/active_storage_validations/matchers/base_comparison_validator_matcher.rb', line 44

def less_than_or_equal_to(value)
  @max = value
  self
end

#matches?(subject) ⇒ Boolean

Returns:

  • (Boolean)


69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/active_storage_validations/matchers/base_comparison_validator_matcher.rb', line 69

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_custom_message_valid? &&
    not_lower_than_min? &&
    higher_than_min? &&
    lower_than_max? &&
    not_higher_than_max? &&
    equal_to_exact? &&
    is_timeout_valid?
end