Class: ActiveStorageValidations::Matchers::ContentTypeValidatorMatcher
- Inherits:
-
Object
- Object
- ActiveStorageValidations::Matchers::ContentTypeValidatorMatcher
- Includes:
- Validatable
- 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.
17 18 19 20 21 |
# File 'lib/active_storage_validations/matchers/content_type_validator_matcher.rb', line 17 def initialize(attribute_name) @attribute_name = attribute_name @allowed_types = @rejected_types = [] @custom_message = nil end |
Instance Method Details
#allowing(*types) ⇒ Object
27 28 29 30 |
# File 'lib/active_storage_validations/matchers/content_type_validator_matcher.rb', line 27 def allowing(*types) @allowed_types = types.flatten self end |
#description ⇒ Object
23 24 25 |
# File 'lib/active_storage_validations/matchers/content_type_validator_matcher.rb', line 23 def description "validate the content types allowed on attachment #{@attribute_name}" end |
#failure_message ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/active_storage_validations/matchers/content_type_validator_matcher.rb', line 51 def = ["Expected #{@attribute_name}"] if @allowed_types_not_allowed.present? << "Accept content types: #{@allowed_types.join(", ")}" << "#{@allowed_types_not_allowed.join(", ")} were rejected" end if @rejected_types_not_rejected.present? << "Reject content types: #{@rejected_types.join(", ")}" << "#{@rejected_types_not_rejected.join(", ")} were accepted" end .join("\n") end |
#matches?(subject) ⇒ Boolean
42 43 44 45 46 47 48 49 |
# File 'lib/active_storage_validations/matchers/content_type_validator_matcher.rb', line 42 def matches?(subject) @subject = subject.is_a?(Class) ? subject.new : subject responds_to_methods && all_allowed_types_allowed? && all_rejected_types_rejected? && end |
#rejecting(*types) ⇒ Object
32 33 34 35 |
# File 'lib/active_storage_validations/matchers/content_type_validator_matcher.rb', line 32 def rejecting(*types) @rejected_types = types.flatten self end |
#with_message(message) ⇒ Object
37 38 39 40 |
# File 'lib/active_storage_validations/matchers/content_type_validator_matcher.rb', line 37 def () @custom_message = self end |