hotdog 0.20.0 → 0.20.1

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: 798b005f303cead90997e9fbff30a5206d2eb56e
4
- data.tar.gz: d4985510ac09a270b1a18a24a1f54e1b61778c7c
3
+ metadata.gz: 6f6979e71063978d355744d1ee83f2f4abd31e87
4
+ data.tar.gz: dca259705e279dcc30dd7732df21efec91d89ed5
5
5
  SHA512:
6
- metadata.gz: 47e9228e056ef41c95b4dd332a1c4dc0856470005b076e9b5abd0e89afdf6d68cea5ddb5e723de84131e506f5110fc074c9760bdd208dd967c0521544328269b
7
- data.tar.gz: 1f174e4a5f7ab4b427dc38c618a69866a6915414c6cf6bce0b51548459a5ef2265b695ca1695b74193cbfaa1b36dd049af9811839ae50c1cc72bcb7aec5cf59d
6
+ metadata.gz: ae9cd27a6872df2ccb09f885ccd57b3a98ab510b276d6f0a014021cee303ef83037893c5bc120288d96017cdeed55e6e9216807464a058673ba5775b196762a6
7
+ data.tar.gz: fc33569232c83c80ac0c4d48defeaa126adb30961539a2a0ff45ae0cd9fb7d4c9d1dd3954ebbef16eed165c05ac1a0aec951c53d409b2685560c0f59f4347b2d
@@ -204,24 +204,38 @@ module Hotdog
204
204
  if @db
205
205
  @db
206
206
  else
207
- FileUtils.mkdir_p(File.dirname(persistent_db_path))
208
- if not options[:force] or options[:offline] or (File.exist?(persistent_db_path) and Time.new < (File.mtime(persistent_db_path) + options[:expiry]))
209
- begin
210
- persistent_db = SQLite3::Database.new(persistent_db_path)
211
- persistent_db.execute("SELECT hosts_tags.host_id FROM hosts_tags INNER JOIN hosts ON hosts_tags.host_id = hosts.id INNER JOIN tags ON hosts_tags.tag_id = tags.id LIMIT 1;")
212
- @db = persistent_db
213
- rescue SQLite3::BusyException
214
- sleep(rand) # FIXME: configurable retry interval
215
- retry
216
- rescue SQLite3::SQLException
217
- if options[:offline]
218
- raise(RuntimeError.new("no database available on offline mode"))
207
+ if options[:force]
208
+ @db = nil
209
+ else
210
+ if options[:offline]
211
+ @db = __open_db(options)
212
+ else
213
+ FileUtils.mkdir_p(File.dirname(persistent_db_path))
214
+ if File.exist?(persistent_db_path) and Time.new <= (File.mtime(persistent_db_path) + options[:expiry])
215
+ @db = __open_db(options)
219
216
  else
220
- persistent_db.close()
217
+ @db = nil
221
218
  end
222
219
  end
223
220
  end
224
- @db
221
+ end
222
+ end
223
+
224
+ def __open_db(options={})
225
+ begin
226
+ persistent_db = SQLite3::Database.new(persistent_db_path)
227
+ persistent_db.execute("SELECT hosts_tags.host_id FROM hosts_tags INNER JOIN hosts ON hosts_tags.host_id = hosts.id INNER JOIN tags ON hosts_tags.tag_id = tags.id LIMIT 1;")
228
+ persistent_db
229
+ rescue SQLite3::BusyException
230
+ sleep(rand) # FIXME: configurable retry interval
231
+ retry
232
+ rescue SQLite3::SQLException
233
+ if options[:offline]
234
+ raise(RuntimeError.new("no database available on offline mode"))
235
+ else
236
+ persistent_db.close()
237
+ nil
238
+ end
225
239
  end
226
240
  end
227
241
 
@@ -1,3 +1,3 @@
1
1
  module Hotdog
2
- VERSION = "0.20.0"
2
+ VERSION = "0.20.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hotdog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.20.0
4
+ version: 0.20.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yamashita Yuu
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-27 00:00:00.000000000 Z
11
+ date: 2017-01-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler