arkaan 1.4.0 → 1.4.1
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 +45 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fddc22f0b04607f2fc9e415ff3d6d7b557936bec
|
4
|
+
data.tar.gz: dfb2e5b7a06d076800c44584154fc9febf13fd37
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0206f995a6d7e37f87da7955dbcdb8f7dc0011202a3a32ff947547a79fb7c0c1cd2da9e3c3112c9767db8f28784ee76baf44dec066f2ee2a64939f963ad21d25
|
7
|
+
data.tar.gz: 27444f0ffbdca19cbb3e085618b01bcc737389c1f8dc9deda271a2906fb4ffefe50847ce87212ca7520e4049d7463c6ea4106c0d8aa0f3450a28b913f5e71f97
|
@@ -15,6 +15,51 @@ module Arkaan
|
|
15
15
|
mime_type ['image/*', 'text/plain']
|
16
16
|
|
17
17
|
validates :name, presence: {message: 'required'}
|
18
|
+
|
19
|
+
validate :name_unicity
|
20
|
+
|
21
|
+
# Checks if the name is unique in the campaign, and if it is not then modifies it.
|
22
|
+
# The modifications are the same than in a windows or UNIX system :
|
23
|
+
# - if the name exists as it is given, the system adds the suffix "(1)" to it.
|
24
|
+
# - if the name with the suffix still exists, the system tries to increment it until an available name is found.
|
25
|
+
# - the found name is then afected to the name of the current file.
|
26
|
+
def name_unicity
|
27
|
+
if !campaign.nil? && !self[:name].nil?
|
28
|
+
if exists_in_campaign(self[:name])
|
29
|
+
suffix = 1
|
30
|
+
while exists_in_campaign(merge_suffix(suffix))
|
31
|
+
suffix = suffix + 1
|
32
|
+
end
|
33
|
+
self[:name] = merge_suffix(suffix)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# Merges the given suffix with the name correctly.
|
39
|
+
# @param suffix [String] the suffix to append between perenthesis at the end of the file name, but before the extension.
|
40
|
+
# @return [String] the complete name for the file, with the suffix correctly appended.
|
41
|
+
def merge_suffix(suffix)
|
42
|
+
return "#{raw_name} (#{suffix}).#{extension}"
|
43
|
+
end
|
44
|
+
|
45
|
+
# Checks if the given name already exists for a file in the campaign.
|
46
|
+
# @param tmp_name [String] the name to check the existence of in the campaign.
|
47
|
+
# @return [Boolean] TRUE if the file exists in the campaign, FALSE otherwise.
|
48
|
+
def exists_in_campaign(tmp_name)
|
49
|
+
campaign.files.where(name: tmp_name, :id.ne => id).exists?
|
50
|
+
end
|
51
|
+
|
52
|
+
# Returns the file name without the extension for the current file.
|
53
|
+
# @return [String] the name of the file without the extension.
|
54
|
+
def raw_name
|
55
|
+
return self[:name].gsub(".#{extension}", '')
|
56
|
+
end
|
57
|
+
|
58
|
+
# Returns the extension of the file, without the dot.
|
59
|
+
# @return [String] the text representation for this file extension, without the leading dot.
|
60
|
+
def extension
|
61
|
+
return self[:name].split('.').last
|
62
|
+
end
|
18
63
|
end
|
19
64
|
end
|
20
65
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: arkaan
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.4.
|
4
|
+
version: 1.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vincent Courtois
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-03-
|
11
|
+
date: 2018-03-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|