attache_rails 0.1.2 → 0.1.3
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 +4 -4
- data/lib/attache_rails/model.rb +16 -4
- data/lib/attache_rails/version.rb +1 -1
- 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: b45396dadc577b1925f04594ce46dc4ceb68519b
|
4
|
+
data.tar.gz: 60b510c900392fa4eef41cdb56caefa94f8b27ec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d4bbcb652c6e56e0e62e903dccef99ed0a7510f4093b062a976dc800824c04062a4266c532cd14b00d1ffd71c8182bf1f2987ef055bad39120ec5e4efd1da44b
|
7
|
+
data.tar.gz: 43597a142f9a65c0a8a81964e9686a7c254c0cc07db6fd96f1ac2e56e2d459380812fc12a04b0caca0a3689f325ad1ed4ee2082fff3e47ae56163be1dd1db554
|
data/lib/attache_rails/model.rb
CHANGED
@@ -5,12 +5,22 @@ require "httpclient"
|
|
5
5
|
module AttacheRails
|
6
6
|
module Utils
|
7
7
|
class << self
|
8
|
+
def attache_retry_doing(max_retries, retries = 0)
|
9
|
+
yield
|
10
|
+
rescue Exception
|
11
|
+
if (retries += 1) <= max_retries
|
12
|
+
sleep retries
|
13
|
+
retry
|
14
|
+
end
|
15
|
+
raise
|
16
|
+
end
|
17
|
+
|
8
18
|
def attache_upload_and_get_json(readable)
|
9
19
|
uri = URI.parse(ATTACHE_UPLOAD_URL)
|
10
20
|
uri.query = { file: (readable.try(:original_filename) || 'noname'), **attache_auth_options }.collect {|k,v|
|
11
21
|
CGI.escape(k.to_s) + "=" + CGI.escape(v.to_s)
|
12
22
|
}.join('&')
|
13
|
-
HTTPClient.post(uri, readable, {'Content-Type' => 'binary/octet-stream'}).body
|
23
|
+
attache_retry_doing(3) { HTTPClient.post(uri, readable, {'Content-Type' => 'binary/octet-stream'}).body }
|
14
24
|
end
|
15
25
|
|
16
26
|
def attache_url_for(json_string, geometry)
|
@@ -41,7 +51,7 @@ module AttacheRails
|
|
41
51
|
placeholder: [*options[:placeholder]],
|
42
52
|
uploadurl: ATTACHE_UPLOAD_URL,
|
43
53
|
downloadurl: ATTACHE_DOWNLOAD_URL,
|
44
|
-
}.merge(options[:
|
54
|
+
}.merge(options[:data] || {}).merge(attache_auth_options),
|
45
55
|
}
|
46
56
|
end
|
47
57
|
end
|
@@ -90,7 +100,9 @@ module AttacheRails
|
|
90
100
|
after_update "#{name}_discard_was"
|
91
101
|
define_method "#{name}_discard", -> do
|
92
102
|
self.attaches_discarded ||= []
|
93
|
-
self.
|
103
|
+
if attrs = self.send("#{name}_attributes", 'original')
|
104
|
+
self.attaches_discarded.push(attrs['path'])
|
105
|
+
end
|
94
106
|
end
|
95
107
|
after_destroy "#{name}_discard"
|
96
108
|
end
|
@@ -109,7 +121,7 @@ module AttacheRails
|
|
109
121
|
super(new_value)
|
110
122
|
}
|
111
123
|
define_method "#{name}_discard_was",-> do
|
112
|
-
new_value = self.send("#{name}")
|
124
|
+
new_value = [*self.send("#{name}")]
|
113
125
|
old_value = [*self.send("#{name}_was")]
|
114
126
|
obsoleted = old_value.collect {|x| JSON.parse(x)['path'] } - new_value.collect {|x| JSON.parse(x)['path'] }
|
115
127
|
self.attaches_discarded ||= []
|