sequel-rack_throttle 0.0.7 → 0.0.8

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 85fbd1c58534479f770bb201a179f68b88563e1f
4
- data.tar.gz: ae2a3c575dfb707c8bb762a2fc589359dcce75a8
3
+ metadata.gz: 6b29e009ceee84cb3672c2f0ccc52b4856b877e7
4
+ data.tar.gz: 5b24579a697cdecb5f4a7167cde201520a20cff3
5
5
  SHA512:
6
- metadata.gz: 7432e5e835760e2f90269c0038fab7d8240ad33286ac5ef01829e74bb2bb8bbafbd02150f6c96927ef3326d569b790b1639373290a69c31c68beb4582ff8e7e3
7
- data.tar.gz: ab55129f21ef08f291388fc524aae365b077ded054582fd785a0cfa64fed04e143d6ad538abfaa07c8ff379f9edca9b48aac48f9f5ed962c0d2243f27fed1158
6
+ metadata.gz: 16588aff4613445c3418768b65620a200f4d25c01a131399f232e2b2ce76af3e2667d8e2ce1d5e507a6809499b784a61f3aee5f29d5a4a93da2e0c26491592a4
7
+ data.tar.gz: c803d5b233e82e74af248c8c55175dc0772e93fd0f1470c866f605789a5eed652814845e20994d2d7edc555b150aff4b1c3c549f07db1c174bfe83dd70050f71
@@ -6,12 +6,8 @@ module Sequel
6
6
  alias_method :old_init, :initialize
7
7
 
8
8
  def initialize(args)
9
+ create_cache_table unless self.cache_table_exists
9
10
  old_init(args)
10
-
11
- create_table? :throttle_cache do
12
- String :key, primary_key: true
13
- Float :value, default: 0
14
- end
15
11
  end
16
12
 
17
13
  def cache_dataset
@@ -19,12 +15,22 @@ module Sequel
19
15
  end
20
16
 
21
17
  def get(key)
18
+ create_cache_table unless self.cache_table_exists
22
19
  (cache_dataset.filter(key: key).first[:value].to_f)
23
20
  end
24
21
 
25
22
  def set(key, value)
23
+ create_cache_table unless self.cache_table_exists
26
24
  unless cache_dataset.where(key: key).update(value: value) == 1 then cache_dataset.insert(key: key, value: value) end
27
25
  end
26
+
27
+ def create_cache_table
28
+ create_table? :throttle_cache do
29
+ String :key, primary_key: true
30
+ Float :value, default: 0
31
+ end
32
+ self.cache_table_exists = true
33
+ end
28
34
  end
29
35
  end
30
36
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sequel-rack_throttle
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gergely Borsothy-Gaal