sequel-rack_throttle 0.0.9 → 0.1.0
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.rb +1 -1
- data/lib/sequel-rack_throttle/ThrottleAdapter.rb +25 -0
- metadata +7 -21
- data/lib/sequel-rack_throttle/Database.rb +0 -36
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 638b888a4c0047bdf0adebfd15e3d7742bd7cb57
|
4
|
+
data.tar.gz: 7b95fb4b9c2842f8e24105a67fba4022f695ade3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 475a2eb566ea507f1a6a246d6857f76c1c04be26da8700f22742896f8bacf58c017869b3555a7064d6239b0b52414e9b9dbcd7e845674230317752a93f84f805
|
7
|
+
data.tar.gz: 93f583662f26b639f234e6764feb8090af719c428e859adf975e22938c9bb4678dde3b71d99c2f4297afea6603cd8437da865b35e1ec02319b97f7090623d26c
|
data/lib/sequel-rack_throttle.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
require_relative 'sequel-rack_throttle/
|
1
|
+
require_relative 'sequel-rack_throttle/ThrottleAdapter'
|
@@ -0,0 +1,25 @@
|
|
1
|
+
class ThrottleAdapter
|
2
|
+
attr_accessor :db, :table
|
3
|
+
|
4
|
+
def initialize(sequel_db, sequel_table = 'throttle_cache')
|
5
|
+
@db = sequel_db
|
6
|
+
@table = sequel_table
|
7
|
+
|
8
|
+
create_table? @table.to_sym do
|
9
|
+
String :key, primary_key: true
|
10
|
+
Float :value, default: 0
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def dataset
|
15
|
+
@db[@table.to_sym]
|
16
|
+
end
|
17
|
+
|
18
|
+
def get(key)
|
19
|
+
(dataset.filter(key: key).first[:value])
|
20
|
+
end
|
21
|
+
|
22
|
+
def set(key, value)
|
23
|
+
unless dataset.where(key: key).update(value: value) == 1 then dataset.insert(key: key, value: value) end
|
24
|
+
end
|
25
|
+
end
|
metadata
CHANGED
@@ -1,38 +1,24 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sequel-rack_throttle
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gergely Borsothy-Gaal
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-02-
|
12
|
-
dependencies:
|
13
|
-
-
|
14
|
-
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - ">="
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ">="
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
27
|
-
description: Sequel patch so you can plug any Sequel-supported database under rack-throttle
|
28
|
-
as a counter.
|
11
|
+
date: 2016-02-19 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A tiny gem for using any Sequel-supported database as a rack-throttle
|
14
|
+
counter cache.
|
29
15
|
email: bggergo@gmail.com
|
30
16
|
executables: []
|
31
17
|
extensions: []
|
32
18
|
extra_rdoc_files: []
|
33
19
|
files:
|
34
20
|
- lib/sequel-rack_throttle.rb
|
35
|
-
- lib/sequel-rack_throttle/
|
21
|
+
- lib/sequel-rack_throttle/ThrottleAdapter.rb
|
36
22
|
homepage: https://github.com/gergelyborsothy/sequel-rack_throttle
|
37
23
|
licenses:
|
38
24
|
- MIT
|
@@ -56,6 +42,6 @@ rubyforge_project:
|
|
56
42
|
rubygems_version: 2.4.5.1
|
57
43
|
signing_key:
|
58
44
|
specification_version: 4
|
59
|
-
summary:
|
45
|
+
summary: Sequal adapter for rack-throttle
|
60
46
|
test_files: []
|
61
47
|
has_rdoc:
|
@@ -1,36 +0,0 @@
|
|
1
|
-
require 'sequel'
|
2
|
-
|
3
|
-
module Sequel
|
4
|
-
module MySQL
|
5
|
-
class Database < Sequel::Database
|
6
|
-
alias_method :old_init, :initialize
|
7
|
-
|
8
|
-
def initialize(args)
|
9
|
-
create_cache_table unless self.cache_table_exists
|
10
|
-
old_init(args)
|
11
|
-
end
|
12
|
-
|
13
|
-
def cache_dataset
|
14
|
-
self[:throttle_cache]
|
15
|
-
end
|
16
|
-
|
17
|
-
def get(key)
|
18
|
-
create_cache_table unless self.cache_table_exists
|
19
|
-
(cache_dataset.filter(key: key).first[:value].to_f)
|
20
|
-
end
|
21
|
-
|
22
|
-
def set(key, value)
|
23
|
-
create_cache_table unless self.cache_table_exists
|
24
|
-
unless cache_dataset.where(key: key).update(value: value) == 1 then cache_dataset.insert(key: key, value: value) end
|
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
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|