Class: ActiveStorageValidations::Matchers::ContentTypeValidatorMatcher
- Inherits:
-
Object
- Object
- ActiveStorageValidations::Matchers::ContentTypeValidatorMatcher
- Defined in:
- lib/active_storage_validations/matchers/content_type_validator_matcher.rb
Instance Method Summary collapse
- #allowing(*types) ⇒ Object
- #description ⇒ Object
- #failure_message ⇒ Object
-
#initialize(attribute_name) ⇒ ContentTypeValidatorMatcher
constructor
A new instance of ContentTypeValidatorMatcher.
- #matches?(subject) ⇒ Boolean
- #rejecting(*types) ⇒ Object
- #with_message(message) ⇒ Object
Constructor Details
#initialize(attribute_name) ⇒ ContentTypeValidatorMatcher
Returns a new instance of ContentTypeValidatorMatcher.
12 13 14 15 |
# File 'lib/active_storage_validations/matchers/content_type_validator_matcher.rb', line 12 def initialize(attribute_name) @attribute_name = attribute_name @custom_message = nil end |
Instance Method Details
#allowing(*types) ⇒ Object
21 22 23 24 |
# File 'lib/active_storage_validations/matchers/content_type_validator_matcher.rb', line 21 def allowing(*types) @allowed_types = types.flatten self end |
#description ⇒ Object
17 18 19 |
# File 'lib/active_storage_validations/matchers/content_type_validator_matcher.rb', line 17 def description "validate the content types allowed on attachment #{@attribute_name}" end |
#failure_message ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/active_storage_validations/matchers/content_type_validator_matcher.rb', line 41 def = ["Expected #{@attribute_name}"] if @allowed_types << "Accept content types: #{allowed_types.join(", ")}" << "#{@missing_allowed_types.join(", ")} were rejected" end if @rejected_types << "Reject content types: #{rejected_types.join(", ")}" << "#{@missing_rejected_types.join(", ")} were accepted" end .join("\n") end |
#matches?(subject) ⇒ Boolean
36 37 38 39 |
# File 'lib/active_storage_validations/matchers/content_type_validator_matcher.rb', line 36 def matches?(subject) @subject = subject.is_a?(Class) ? subject.new : subject responds_to_methods && allowed_types_allowed? && rejected_types_rejected? && end |
#rejecting(*types) ⇒ Object
26 27 28 29 |
# File 'lib/active_storage_validations/matchers/content_type_validator_matcher.rb', line 26 def rejecting(*types) @rejected_types = types.flatten self end |
#with_message(message) ⇒ Object
31 32 33 34 |
# File 'lib/active_storage_validations/matchers/content_type_validator_matcher.rb', line 31 def () @custom_message = self end |