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 +4 -4
- data/lib/sequel-rack_throttle/Database.rb +11 -5
- 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: 6b29e009ceee84cb3672c2f0ccc52b4856b877e7
|
4
|
+
data.tar.gz: 5b24579a697cdecb5f4a7167cde201520a20cff3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|