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
Constructor Details
#initialize(attribute_name) ⇒ ContentTypeValidatorMatcher
Returns a new instance of ContentTypeValidatorMatcher.
12 13 14 |
# File 'lib/active_storage_validations/matchers/content_type_validator_matcher.rb', line 12 def initialize(attribute_name) @attribute_name = attribute_name end |
Instance Method Details
#allowing(*types) ⇒ Object
20 21 22 23 |
# File 'lib/active_storage_validations/matchers/content_type_validator_matcher.rb', line 20 def allowing(*types) @allowed_types = types.flatten self end |
#description ⇒ Object
16 17 18 |
# File 'lib/active_storage_validations/matchers/content_type_validator_matcher.rb', line 16 def description "validate the content types allowed on attachment #{@attribute_name}" end |
#failure_message ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/active_storage_validations/matchers/content_type_validator_matcher.rb', line 35 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
30 31 32 33 |
# File 'lib/active_storage_validations/matchers/content_type_validator_matcher.rb', line 30 def matches?(subject) @subject = subject.is_a?(Class) ? subject.new : subject responds_to_methods && allowed_types_allowed? && rejected_types_rejected? end |
#rejecting(*types) ⇒ Object
25 26 27 28 |
# File 'lib/active_storage_validations/matchers/content_type_validator_matcher.rb', line 25 def rejecting(*types) @rejected_types = types.flatten self end |