arkaan 1.3.3 → 1.3.4
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 -5
- data/lib/arkaan/concerns.rb +1 -0
- data/lib/arkaan/concerns/mime_typable.rb +32 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 19efb40b34e772295e2e3d88d2d420c5f89259df
|
4
|
+
data.tar.gz: fb73957a53d5ba35423d94c889bb0357272a262a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9d3d4e798060c3bba039c5a670332cb66063955e10b7caa4d5811584bbc2cf02bde8c618826a17f7f4bed8aeb90c7ba621fea6c691ebeb319b7912c8122f0914
|
7
|
+
data.tar.gz: 1243cec2b101cc1dbe77503e2b353de557875e1c74b99b60b39bf269be7c89bc0c817a6841928436b4b47a8c48851767548ca0c2af430ce30d54ce5785e348eb
|
@@ -5,6 +5,7 @@ module Arkaan
|
|
5
5
|
class File
|
6
6
|
include Mongoid::Document
|
7
7
|
include Mongoid::Timestamps
|
8
|
+
include Arkaan::Concerns::MimeTypable
|
8
9
|
|
9
10
|
# @!attribute [rw] filename
|
10
11
|
# @return [String] the name of the file, corresponding to the AWS name.
|
@@ -12,16 +13,12 @@ module Arkaan
|
|
12
13
|
# @!attribute [rw] size
|
13
14
|
# @return [Integer] the size of the file in bytes.
|
14
15
|
field :size, type: Integer, default: 0
|
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
|
18
16
|
|
19
17
|
# @!attribute [rw] invitation
|
20
18
|
# @return [Arkaan::Campaigns::Invitation] the link to the user creator of the file and the campaign it's created in.
|
21
19
|
embedded_in :invitation, class_name: 'Arkaan::Campaigns::Invitation', inverse_of: :files
|
22
20
|
|
23
|
-
validates
|
24
|
-
validates 'mime_type', presence: {message: 'required'}
|
21
|
+
validates :name , presence: {message: 'required'}
|
25
22
|
end
|
26
23
|
end
|
27
24
|
end
|
data/lib/arkaan/concerns.rb
CHANGED
@@ -5,6 +5,7 @@ module Arkaan
|
|
5
5
|
autoload :Activable , 'arkaan/concerns/activable'
|
6
6
|
autoload :Diagnosticable, 'arkaan/concerns/diagnosticable'
|
7
7
|
autoload :Enumerable , 'arkaan/concerns/enumerable'
|
8
|
+
autoload :MimeTypable , 'arkaan/concerns/mime_typable'
|
8
9
|
autoload :Premiumable , 'arkaan/concerns/premiumable'
|
9
10
|
autoload :Sluggable , 'arkaan/concerns/sluggable'
|
10
11
|
autoload :Typable , 'arkaan/concerns/typable'
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Arkaan
|
2
|
+
module Concerns
|
3
|
+
# Includes the MIME type field to files to ensure only supported types are included.
|
4
|
+
# @author Vincent Courtois <courtois.vincent@outlook.com>
|
5
|
+
module MimeTypable
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
# Module holding the class methods for the classes including this concern.
|
9
|
+
# @author Vincent Courtois <courtois.vincent@outlook.com>
|
10
|
+
included do
|
11
|
+
# @!attribute [rw] mime_type
|
12
|
+
# @return [String] the MIME type of the file, obtained from the uploaded file.
|
13
|
+
field :mime_type, type: String
|
14
|
+
|
15
|
+
validates :mime_type, presence: {message: 'required'}
|
16
|
+
|
17
|
+
validate :mime_type_validity, if: :mime_type?
|
18
|
+
|
19
|
+
# Validates the validity of the MIME type by checking if it respects any of the given mime types.
|
20
|
+
# If it does not respect any MIME types possible, it adds an error to the mime_type field and invalidates.
|
21
|
+
def mime_type_validity
|
22
|
+
accepted = ['image/*', 'text/plain']
|
23
|
+
accepted.each do |type|
|
24
|
+
type_regex = ::Regexp.new("^#{type.sub(/\*/, '(.+)')}$")
|
25
|
+
return true if !type_regex.match(mime_type).nil?
|
26
|
+
end
|
27
|
+
errors.add(:mime_type, 'pattern')
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: arkaan
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vincent Courtois
|
@@ -268,6 +268,7 @@ files:
|
|
268
268
|
- lib/arkaan/concerns/activable.rb
|
269
269
|
- lib/arkaan/concerns/diagnosticable.rb
|
270
270
|
- lib/arkaan/concerns/enumerable.rb
|
271
|
+
- lib/arkaan/concerns/mime_typable.rb
|
271
272
|
- lib/arkaan/concerns/premiumable.rb
|
272
273
|
- lib/arkaan/concerns/sluggable.rb
|
273
274
|
- lib/arkaan/concerns/typable.rb
|