Class: ActiveStorageValidations::Matchers::AttachedValidatorMatcher

Inherits:
Object
  • Object
show all
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.



10
11
12
# File 'lib/active_storage_validations/matchers/attached_validator_matcher.rb', line 10

def initialize(attribute_name)
  @attribute_name = attribute_name
end

Instance Method Details

#descriptionObject



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

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

#failure_messageObject



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

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

#failure_message_when_negatedObject



27
28
29
# File 'lib/active_storage_validations/matchers/attached_validator_matcher.rb', line 27

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

#matches?(subject) ⇒ Boolean

Returns:

  • (Boolean)


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

def matches?(subject)
  @subject = subject.is_a?(Class) ? subject.new : subject
  responds_to_methods && valid_when_attached && invalid_when_not_attached
end