arkaan 1.3.4 → 1.3.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 19efb40b34e772295e2e3d88d2d420c5f89259df
4
- data.tar.gz: fb73957a53d5ba35423d94c889bb0357272a262a
3
+ metadata.gz: d2abfbdbc0cad893f79ed3b3b42616ef1a8bdf01
4
+ data.tar.gz: fc96c9ede1c2f95558f786391abaed4dc8868a2f
5
5
  SHA512:
6
- metadata.gz: 9d3d4e798060c3bba039c5a670332cb66063955e10b7caa4d5811584bbc2cf02bde8c618826a17f7f4bed8aeb90c7ba621fea6c691ebeb319b7912c8122f0914
7
- data.tar.gz: 1243cec2b101cc1dbe77503e2b353de557875e1c74b99b60b39bf269be7c89bc0c817a6841928436b4b47a8c48851767548ca0c2af430ce30d54ce5785e348eb
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
- # Module holding the class methods for the classes including this concern.
8
+ # Submodule holding all the static methods add to the current subclass.
9
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
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
- validates :mime_type, presence: {message: 'required'}
19
+ validates :mime_type, presence: {message: 'required'}
16
20
 
17
- validate :mime_type_validity, if: :mime_type?
21
+ validate :mime_type_validity, if: :mime_type?
18
22
 
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?
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
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
4
+ version: 1.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vincent Courtois