Class: ActiveStorageValidations::Matchers::AttachedValidatorMatcher

Inherits:
Object
  • Object
show all
Includes:
Validatable
Defined in:
lib/active_storage_validations/matchers/attached_validator_matcher.rb

Instance Method Summary collapse

Constructor Details

#initialize(attribute_name) ⇒ AttachedValidatorMatcher

Returns a new instance of AttachedValidatorMatcher.



14
15
16
17
# File 'lib/active_storage_validations/matchers/attached_validator_matcher.rb', line 14

def initialize(attribute_name)
  @attribute_name = attribute_name
  @custom_message = nil
end

Instance Method Details

#descriptionObject



19
20
21
# File 'lib/active_storage_validations/matchers/attached_validator_matcher.rb', line 19

def description
  "validate #{@attribute_name} must be attached"
end

#failure_messageObject



36
37
38
# File 'lib/active_storage_validations/matchers/attached_validator_matcher.rb', line 36

def failure_message
  "is expected to validate attached of #{@attribute_name}"
end

#failure_message_when_negatedObject



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

def failure_message_when_negated
  "is expected to not validate attached of #{@attribute_name}"
end

#matches?(subject) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
31
32
33
34
# File 'lib/active_storage_validations/matchers/attached_validator_matcher.rb', line 28

def matches?(subject)
  @subject = subject.is_a?(Class) ? subject.new : subject
  responds_to_methods &&
    is_valid_when_file_attached? &&
    is_invalid_when_file_not_attached? &&
    validate_custom_message?
end

#with_message(message) ⇒ Object



23
24
25
26
# File 'lib/active_storage_validations/matchers/attached_validator_matcher.rb', line 23

def with_message(message)
  @custom_message = message
  self
end