uploadcare-rails 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
@@ -4,31 +4,45 @@ module Uploadcare
|
|
4
4
|
def is_uploadcare_file attribute, options = {}
|
5
5
|
options.symbolize_keys!
|
6
6
|
opts = {
|
7
|
-
autostore: true
|
7
|
+
autostore: true,
|
8
|
+
force_autostore: false
|
8
9
|
}.update options
|
9
10
|
|
11
|
+
get_uuid = lambda do |attributes|
|
12
|
+
re = /[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}/i
|
13
|
+
m = re.match(attributes[attribute.to_s])
|
14
|
+
if m.nil?
|
15
|
+
nil
|
16
|
+
else
|
17
|
+
m[0]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
10
21
|
define_method "#{attribute}" do
|
11
|
-
|
22
|
+
uuid = get_uuid.call(attributes)
|
23
|
+
return nil unless uuid
|
12
24
|
|
13
25
|
if instance_variable_defined?("@#{attribute}_cached")
|
14
26
|
instance_variable_get("@#{attribute}_cached")
|
15
27
|
else
|
16
|
-
|
17
|
-
m = re.match(attributes[attribute.to_s])
|
18
|
-
return nil if m.nil?
|
19
|
-
|
20
|
-
file_data = ::Rails.application.config.uploadcare.api.file(m[0])
|
28
|
+
file_data = ::Rails.application.config.uploadcare.api.file(uuid)
|
21
29
|
instance_variable_set("@#{attribute}_cached", file_data)
|
22
30
|
file_data
|
23
31
|
end
|
24
32
|
end
|
25
33
|
|
26
34
|
if opts[:autostore]
|
27
|
-
|
35
|
+
after_save "store_#{attribute}"
|
28
36
|
|
29
37
|
define_method "store_#{attribute}" do
|
30
|
-
|
38
|
+
uuid = get_uuid.call(attributes)
|
39
|
+
stored = ::Rails.cache.exist?(
|
40
|
+
"uploadcare.file.#{uuid}.store",
|
41
|
+
force: opts[:force_autostore]
|
42
|
+
)
|
43
|
+
unless stored
|
31
44
|
send(attribute).store
|
45
|
+
::Rails.cache.write("uploadcare.file.#{uuid}.store", true)
|
32
46
|
end
|
33
47
|
end
|
34
48
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: uploadcare-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-04-
|
12
|
+
date: 2013-04-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -124,7 +124,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
124
124
|
version: '0'
|
125
125
|
segments:
|
126
126
|
- 0
|
127
|
-
hash:
|
127
|
+
hash: -518698960582409353
|
128
128
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
129
129
|
none: false
|
130
130
|
requirements:
|
@@ -133,7 +133,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
133
133
|
version: '0'
|
134
134
|
segments:
|
135
135
|
- 0
|
136
|
-
hash:
|
136
|
+
hash: -518698960582409353
|
137
137
|
requirements: []
|
138
138
|
rubyforge_project:
|
139
139
|
rubygems_version: 1.8.24
|