attache_rails 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 71bdf794a1a45cfb4a1c5a1f009a6b0986c2f036
4
- data.tar.gz: aa0fd8c6977c2e78ae9114d3e53aa9a24ac3972e
3
+ metadata.gz: b45396dadc577b1925f04594ce46dc4ceb68519b
4
+ data.tar.gz: 60b510c900392fa4eef41cdb56caefa94f8b27ec
5
5
  SHA512:
6
- metadata.gz: f83391852c79448f278812211b2fb9dbc9f61302da3049e3e9f1a80e346c515c0bcbe4ab4fd12e859f2d0df9c246c3692d296bd320268a3a613a36f3d3afcee0
7
- data.tar.gz: d6a3d6c02e9d3aaf54beb9567da08238b91464270d4daf4edd8ce6602c4d279d8284e88f836e309b166135e221e22f67355190af8919356dfdb4deddc88fd194
6
+ metadata.gz: d4bbcb652c6e56e0e62e903dccef99ed0a7510f4093b062a976dc800824c04062a4266c532cd14b00d1ffd71c8182bf1f2987ef055bad39120ec5e4efd1da44b
7
+ data.tar.gz: 43597a142f9a65c0a8a81964e9686a7c254c0cc07db6fd96f1ac2e56e2d459380812fc12a04b0caca0a3689f325ad1ed4ee2082fff3e47ae56163be1dd1db554
@@ -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[:data_attrs] || {}).merge(attache_auth_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.attaches_discarded.push(self.send("#{name}_attributes", 'original')['path'])
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 ||= []
@@ -1,3 +1,3 @@
1
1
  module AttacheRails
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: attache_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - choonkeat