arkaan 1.3.4 → 1.3.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/arkaan/campaigns/file.rb +2 -0
- data/lib/arkaan/concerns/mime_typable.rb +19 -15
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d2abfbdbc0cad893f79ed3b3b42616ef1a8bdf01
|
4
|
+
data.tar.gz: fc96c9ede1c2f95558f786391abaed4dc8868a2f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '0438f9b21305372053ecf6e3cfa44348e9eb27084d34856c41011e046218f51f0e6ed715914443de6e421a8a21b07f5606bb5661bbbb8fbe2532aee03e0fd0ce'
|
7
|
+
data.tar.gz: c47f0f473589c893fee3cd8ad4d1f9f4f10a9d62ad0ec61a4f52625a6c7d94985670b914b516fb1e399a1375a95495fc5badab5aab9ce5652abcae0c502f6f59
|
@@ -14,6 +14,8 @@ module Arkaan
|
|
14
14
|
# @return [Integer] the size of the file in bytes.
|
15
15
|
field :size, type: Integer, default: 0
|
16
16
|
|
17
|
+
mime_type ['image/*', 'text/plain']
|
18
|
+
|
17
19
|
# @!attribute [rw] invitation
|
18
20
|
# @return [Arkaan::Campaigns::Invitation] the link to the user creator of the file and the campaign it's created in.
|
19
21
|
embedded_in :invitation, class_name: 'Arkaan::Campaigns::Invitation', inverse_of: :files
|
@@ -5,26 +5,30 @@ module Arkaan
|
|
5
5
|
module MimeTypable
|
6
6
|
extend ActiveSupport::Concern
|
7
7
|
|
8
|
-
#
|
8
|
+
# Submodule holding all the static methods add to the current subclass.
|
9
9
|
# @author Vincent Courtois <courtois.vincent@outlook.com>
|
10
|
-
|
11
|
-
#
|
12
|
-
#
|
13
|
-
|
10
|
+
module ClassMethods
|
11
|
+
# Defines the MIME type attribute with the given possible MIME types.
|
12
|
+
# @param values [Array<String>] the possible MIME types, * can be used as wild cards.
|
13
|
+
def mime_type(values)
|
14
|
+
|
15
|
+
# @!attribute [rw] mime_type
|
16
|
+
# @return [String] the MIME type of the file, obtained from the uploaded file.
|
17
|
+
field :mime_type, type: String
|
14
18
|
|
15
|
-
|
19
|
+
validates :mime_type, presence: {message: 'required'}
|
16
20
|
|
17
|
-
|
21
|
+
validate :mime_type_validity, if: :mime_type?
|
18
22
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
23
|
+
# Validates the validity of the MIME type by checking if it respects any of the given mime types.
|
24
|
+
# If it does not respect any MIME types possible, it adds an error to the mime_type field and invalidates.
|
25
|
+
define_method :mime_type_validity do
|
26
|
+
values.each do |type|
|
27
|
+
type_regex = ::Regexp.new("^#{type.sub(/\*/, '(.+)')}$")
|
28
|
+
return true if !type_regex.match(mime_type).nil?
|
29
|
+
end
|
30
|
+
errors.add(:mime_type, 'pattern')
|
26
31
|
end
|
27
|
-
errors.add(:mime_type, 'pattern')
|
28
32
|
end
|
29
33
|
end
|
30
34
|
end
|