redis-throttler 0.1.7 → 0.1.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: d495303bb5a7733b5fd5feb751563a505d700db5
4
- data.tar.gz: 5c8defae79ace760ed398e9d8565ce642dfbe11c
3
+ metadata.gz: d9048c65a94779c20e6b3c3218c819eed086199f
4
+ data.tar.gz: 0c651759bc3353b53bc35e556585c5a6b9f9bf21
5
5
  SHA512:
6
- metadata.gz: 8fc82355c9e9a62a1f06501be6eedc76231d7a0c9b90f5f3fe21730cd32cfbd476c4e6520901b69a11a5ebca9fb173d158baacf786d0f9455b8b2183e6d188c0
7
- data.tar.gz: 9909db6de4dd0a69f075eb5ca6e91c345b4d7e5d6f35bdc2fc36d5e0efaa912a3f7aa42b145143c82cd13bb07ffcaf2407923ad13f13c812463c42ad34f7ac24
6
+ metadata.gz: 9efc8ea572856bfadc8b81a076c8367ec83c624688488eb5b3c4ebaffcc390805370e1964efd10ea2e26de3c7c7b6087fb16880c97446e64a4317a8de0660641
7
+ data.tar.gz: cbfaa0d75eeb21064873e2ec7df7ec795c37e0dbd59abc1b677804dee57d17a981437aa6e775408e45c7930fa93af1dc5ade6b76a9f69b24ff056949238fc325
data/ChangeLog.md CHANGED
@@ -1,3 +1,8 @@
1
+ ### 0.1.8 / 2016-08-02:
2
+
3
+ * Add Configuration helper to allow for initializer
4
+ * Add test for configuration
5
+
1
6
  ### 0.1.7 / 2016-08-01:
2
7
 
3
8
  * Fix test specs
@@ -114,7 +114,7 @@ module RedisThrottler
114
114
  end
115
115
 
116
116
  def redis
117
- @redis ||= Redis.new(host: '192.168.99.100', port: 32768)
117
+ @redis ||= RedisThrottler.redis
118
118
  end
119
119
  end
120
120
  end
@@ -0,0 +1,29 @@
1
+ module RedisThrottler
2
+ module Configuration
3
+
4
+ def configuration
5
+ yield self
6
+ end
7
+
8
+ def define_setting(name, default = nil)
9
+ class_variable_set("@@#{name}", default)
10
+
11
+ define_class_method "#{name}=" do |value|
12
+ class_variable_set("@@#{name}", value)
13
+ end
14
+
15
+ define_class_method name do
16
+ class_variable_get("@@#{name}")
17
+ end
18
+ end
19
+
20
+ private
21
+
22
+ def define_class_method(name, &block)
23
+ (class << self; self; end).instance_eval do
24
+ define_method name, &block
25
+ end
26
+ end
27
+
28
+ end
29
+ end
@@ -14,8 +14,8 @@ module RedisThrottler
14
14
  key = "#{key.to_s}"
15
15
 
16
16
  subject = opts[:by] || :id
17
- limit = opts[:limit] || 5
18
- threshold = opts[:for] || 900
17
+ limit = opts[:limit] || RedisThrottler.default_limit
18
+ threshold = opts[:for] || RedisThrottler.default_threshold
19
19
  interval = opts[:interval] || ([threshold,120].max)/120
20
20
  bucket_span = threshold * 2
21
21
 
@@ -1,3 +1,3 @@
1
1
  module RedisThrottler
2
- VERSION = '0.1.7'
2
+ VERSION = '0.1.8'
3
3
  end
@@ -1,8 +1,17 @@
1
1
  require 'redis'
2
+ require 'redis-throttler/configuration'
2
3
  require 'redis-throttler/model'
3
4
  require 'redis-throttler/base'
4
5
 
6
+
5
7
  module RedisThrottler
8
+ extend RedisThrottler::Configuration
9
+
10
+ define_setting :default_limit, 5
11
+ define_setting :default_threshold, 600
12
+
13
+ define_setting :redis, Redis.new(host: 'localhost', port: 6379)
14
+
6
15
  def self.included(base)
7
16
  base.include(RedisThrottler::Model)
8
17
  end
data/spec/spec_helper.rb CHANGED
@@ -5,7 +5,7 @@ require 'timecop'
5
5
 
6
6
  class TestClass
7
7
  include RedisThrottler
8
- throttle :logins, limit: 10, for: 5000
8
+ throttle :logins, limit: 10, for: 3600
9
9
 
10
10
  def initialize
11
11
  @id = 1234
@@ -7,6 +7,20 @@ describe RedisThrottler::Base do
7
7
  @rl.send(:redis).flushdb
8
8
  end
9
9
 
10
+ it 'configures properly' do
11
+ expect(RedisThrottler.default_limit).to eq(5)
12
+ expect(RedisThrottler.default_threshold).to eq(600)
13
+ expect(RedisThrottler.redis).to be_a(Redis)
14
+
15
+ RedisThrottler.configuration do |config|
16
+ config.default_limit = 10
17
+ config.default_threshold = 900
18
+ end
19
+
20
+ expect(RedisThrottler.default_limit).to eq(10)
21
+ expect(RedisThrottler.default_threshold).to eq(900)
22
+ end
23
+
10
24
  it 'sets set_bucket_expiry to the bucket_span if not defined' do
11
25
  expect(@rl.instance_variable_get(:@bucket_span)).to eq(@rl.instance_variable_get(:@bucket_expiry))
12
26
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redis-throttler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Evan Surdam
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-01 00:00:00.000000000 Z
11
+ date: 2016-08-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis
@@ -129,6 +129,7 @@ files:
129
129
  - gemspec.yml
130
130
  - lib/redis-throttler.rb
131
131
  - lib/redis-throttler/base.rb
132
+ - lib/redis-throttler/configuration.rb
132
133
  - lib/redis-throttler/model.rb
133
134
  - lib/redis-throttler/version.rb
134
135
  - redis-throttler.gemspec