ratelimit 0.0.3 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.document +5 -0
- data/.gitignore +22 -0
- data/.rspec +3 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +10 -0
- data/CHANGELOG +11 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +22 -0
- data/README.md +62 -0
- data/Rakefile +38 -0
- data/lib/ratelimit.rb +21 -16
- data/lib/ratelimit/version.rb +3 -0
- data/ratelimit.gemspec +31 -0
- data/spec/ratelimit_spec.rb +95 -0
- data/spec/spec_helper.rb +84 -0
- metadata +154 -20
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d3469b758aeb6c99ad1c09a4d29592c577fa763d
|
4
|
+
data.tar.gz: 99d79d9a382c81ed8ac69cd3b296423768d6d70e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5c4de3a5f289954c3739da0b7741cc20aa98c03f052a5cc91ab175155551ce3f64c572bb49266563392dea094f32b5a2b8cc095b7731d37cf3f9c7aa0143b840
|
7
|
+
data.tar.gz: 58bb9fb868721df9c6c03475300be40c22288260b612f562d69ee06cadb9e6ba015292349a80f500b6ad47d4b220641a96af6d3eeddebcd531c24625efdbf9f4
|
data/.document
ADDED
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/.rspec
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ratelimit
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.1.1
|
data/.travis.yml
ADDED
data/CHANGELOG
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
0.0.2 10/29/2011 38422666592c32dc079fd46bb41b5f526a7cf1d2
|
2
|
+
=========================================================
|
3
|
+
|
4
|
+
Initial Relase
|
5
|
+
|
6
|
+
|
7
|
+
0.0.3 11/08/2011 b5b81dcc488f231b6a7abbdeb87c7ddf247b4029
|
8
|
+
=========================================================
|
9
|
+
|
10
|
+
Allow non-string subject and key -- Thanks Alexey Noskov
|
11
|
+
Fix for bucket_expiry allowed to be larger than bucket_span and causing bad results -- Thanks Alexey Noskov
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 E.J. Finneran
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
# Ratelimit: Slow your roll
|
2
|
+
|
3
|
+
[![Build Status](https://secure.travis-ci.org/ejfinneran/ratelimit.png?branch=master)](http://travis-ci.org/ejfinneran/ratelimit)
|
4
|
+
[![Code Climate](https://codeclimate.com/github/ejfinneran/ratelimit.png)](https://codeclimate.com/github/ejfinneran/ratelimit)
|
5
|
+
[![Coverage Status](https://coveralls.io/repos/ejfinneran/ratelimit/badge.png)](https://coveralls.io/r/ejfinneran/ratelimit)
|
6
|
+
|
7
|
+
Ratelimit provides a way to rate limit actions across multiple servers using Redis. This is a port of RateLimit.js found [here](https://github.com/chriso/redback/blob/master/lib/advanced_structures/RateLimit.js) and inspired by [this post](http://chris6f.com/rate-limiting-with-redis).
|
8
|
+
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
gem 'ratelimit'
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
$ gem install ratelimit
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
My example use case is bulk processing data against an external API. This will allow you to limit multiple processes across multiple servers as long as they all use the same Redis database.
|
27
|
+
|
28
|
+
Add to the count for a given subject via add with a unique key. I've used the example of a phone number below but anything unique would work (URL, email address, etc.)
|
29
|
+
|
30
|
+
You can then fetch the number of executions for given interval in seconds via the count method.
|
31
|
+
|
32
|
+
ratelimit = Ratelimit.new("messages")
|
33
|
+
5.times do
|
34
|
+
ratelimit.add(phone_number)
|
35
|
+
end
|
36
|
+
ratelimit.count(phone_number, 30)
|
37
|
+
=> 5
|
38
|
+
|
39
|
+
You can check if a given threshold has been exceeded or not. The following code checks if the currently rate is over 10 executions in the last 30 seconds or not.
|
40
|
+
|
41
|
+
ratelimit.exceeded?(phone_number, {:threshold => 10, :interval => 30})
|
42
|
+
=> false
|
43
|
+
ratelimit.within_bounds?(phone_number, {:threshold => 10, :interval => 30})
|
44
|
+
=> true
|
45
|
+
|
46
|
+
You can also pass a block that will only get executed if the given threshold is within bounds. Beware, this code blocks until the block can be run.
|
47
|
+
|
48
|
+
ratelimit.exec_within_threshold(phone_number, {:threshold => 10, :interval => 30}) do
|
49
|
+
some_rate_limited_code
|
50
|
+
end
|
51
|
+
|
52
|
+
## Documentation
|
53
|
+
|
54
|
+
Full documentation can be found [here.](http://rubydoc.info/github/ejfinneran/ratelimit/frames)
|
55
|
+
|
56
|
+
## Contributing
|
57
|
+
|
58
|
+
1. Fork it ( https://github.com/ejfinneran/ratelimit/fork )
|
59
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
60
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
61
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
62
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
|
3
|
+
require 'rake/testtask'
|
4
|
+
|
5
|
+
Rake::TestTask.new(:test) do |test|
|
6
|
+
test.libs << 'lib' << 'test'
|
7
|
+
test.test_files = FileList['test/**/test_*.rb']
|
8
|
+
test.verbose = true
|
9
|
+
end
|
10
|
+
|
11
|
+
task :default => :test
|
12
|
+
|
13
|
+
namespace :doc do
|
14
|
+
project_root = File.dirname(__FILE__)
|
15
|
+
doc_destination = File.join(project_root, 'rdoc')
|
16
|
+
|
17
|
+
begin
|
18
|
+
require 'rdoc'
|
19
|
+
require 'yard'
|
20
|
+
require 'yard/rake/yardoc_task'
|
21
|
+
|
22
|
+
YARD::Rake::YardocTask.new(:generate) do |yt|
|
23
|
+
yt.files = Dir.glob(File.join(project_root, 'lib', '**', '*.rb'))
|
24
|
+
yt.options = ['--output-dir', doc_destination, '--readme', 'README.md']
|
25
|
+
end
|
26
|
+
rescue LoadError
|
27
|
+
desc "Generate YARD Documentation"
|
28
|
+
task :generate do
|
29
|
+
abort "Please install the YARD gem to generate rdoc."
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
desc "Remove generated documenation"
|
34
|
+
task :clean do
|
35
|
+
rm_r doc_dir if File.exists?(doc_destination)
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
data/lib/ratelimit.rb
CHANGED
@@ -6,36 +6,44 @@ class Ratelimit
|
|
6
6
|
# Create a RateLimit object.
|
7
7
|
#
|
8
8
|
# @param [String] key A name to uniquely identify this rate limit. For example, 'emails'
|
9
|
-
# @param [Redis] redis Redis instance to use. One is created if nothing is passed.
|
10
9
|
# @param [Hash] options Options hash
|
11
10
|
# @option options [Integer] :bucket_span (600) Time span to track in seconds
|
12
11
|
# @option options [Integer] :bucket_interval (5) How many seconds each bucket represents
|
13
12
|
# @option options [Integer] :bucket_expiry (@bucket_span) How long we keep data in each bucket before it is auto expired. Cannot be larger than the bucket_span.
|
13
|
+
# @option options [Redis] :redis (nil) Redis client if you need to customize connection options
|
14
14
|
#
|
15
15
|
# @return [RateLimit] RateLimit instance
|
16
16
|
#
|
17
|
-
def initialize(key,
|
17
|
+
def initialize(key, options = {})
|
18
18
|
@key = key
|
19
|
+
unless options.is_a?(Hash)
|
20
|
+
raise ArgumentError.new("Redis object is now passed in via the options hash - options[:redis]")
|
21
|
+
end
|
19
22
|
@bucket_span = options[:bucket_span] || 600
|
20
23
|
@bucket_interval = options[:bucket_interval] || 5
|
21
24
|
@bucket_expiry = options[:bucket_expiry] || @bucket_span
|
22
|
-
|
25
|
+
if @bucket_expiry > @bucket_span
|
26
|
+
raise ArgumentError.new("Bucket expiry cannot be larger than the bucket span")
|
27
|
+
end
|
23
28
|
@bucket_count = (@bucket_span / @bucket_interval).round
|
24
|
-
@redis = redis
|
29
|
+
@redis = options[:redis]
|
25
30
|
end
|
26
31
|
|
27
32
|
# Add to the counter for a given subject.
|
28
33
|
#
|
29
|
-
# @param [String]
|
30
|
-
|
34
|
+
# @param [String] subject A unique key to identify the subject. For example, 'user@foo.com'
|
35
|
+
# @param [Integer] count The number by which to increase the counter
|
36
|
+
#
|
37
|
+
# @return [Integer] The counter value
|
38
|
+
def add(subject, count = 1)
|
31
39
|
bucket = get_bucket
|
32
40
|
subject = "#{@key}:#{subject}"
|
33
|
-
redis.
|
34
|
-
redis.hincrby(subject, bucket,
|
41
|
+
redis.pipelined do
|
42
|
+
redis.hincrby(subject, bucket, count)
|
35
43
|
redis.hdel(subject, (bucket + 1) % @bucket_count)
|
36
44
|
redis.hdel(subject, (bucket + 2) % @bucket_count)
|
37
45
|
redis.expire(subject, @bucket_expiry)
|
38
|
-
end
|
46
|
+
end.first
|
39
47
|
end
|
40
48
|
|
41
49
|
# Returns the count for a given subject and interval
|
@@ -47,14 +55,11 @@ class Ratelimit
|
|
47
55
|
interval = [interval, @bucket_interval].max
|
48
56
|
count = (interval / @bucket_interval).floor
|
49
57
|
subject = "#{@key}:#{subject}"
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
bucket -= 1
|
54
|
-
redis.hget(subject, (bucket + @bucket_count) % @bucket_count)
|
55
|
-
end
|
58
|
+
|
59
|
+
keys = (0..count).map do |i|
|
60
|
+
(bucket - i + @bucket_count) % @bucket_count
|
56
61
|
end
|
57
|
-
return
|
62
|
+
return redis.hmget(subject, *keys).inject(0) {|a, i| a + i.to_i}
|
58
63
|
end
|
59
64
|
|
60
65
|
# Check if the rate limit has been exceeded.
|
data/ratelimit.gemspec
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'ratelimit/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "ratelimit"
|
8
|
+
spec.version = Ratelimit::VERSION
|
9
|
+
spec.authors = ["E.J. Finneran"]
|
10
|
+
spec.email = ["ej.finneran@gmail.com"]
|
11
|
+
spec.summary = "Rate limiting backed by redis"
|
12
|
+
spec.description = "This library uses Redis to track the number of actions for a given subject over a flexible time frame."
|
13
|
+
spec.homepage = "https://github.com/ejfinneran/ratelimit"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "redis", ">= 2.0.0"
|
22
|
+
spec.add_dependency "redis-namespace", ">= 1.0.0"
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
spec.add_development_dependency "fakeredis"
|
26
|
+
spec.add_development_dependency "timecop"
|
27
|
+
spec.add_development_dependency "rspec"
|
28
|
+
spec.add_development_dependency "yard"
|
29
|
+
spec.add_development_dependency "maruku"
|
30
|
+
spec.add_development_dependency "rdoc"
|
31
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Ratelimit do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@r = Ratelimit.new("key")
|
7
|
+
@r.send(:redis).flushdb
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should set_bucket_expiry to the bucket_span if not defined" do
|
11
|
+
expect(@r.instance_variable_get(:@bucket_span)).to eq(@r.instance_variable_get(:@bucket_expiry))
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should not allow bucket expiry to be larger than the bucket span" do
|
15
|
+
expect do
|
16
|
+
Ratelimit.new("key", {:bucket_expiry => 1200})
|
17
|
+
end.to raise_error(ArgumentError)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should not allow redis to be passed outside of the options hash" do
|
21
|
+
expect do
|
22
|
+
Ratelimit.new("key", Redis.new)
|
23
|
+
end.to raise_error(ArgumentError)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should be able to add to the count for a given subject" do
|
27
|
+
@r.add("value1")
|
28
|
+
@r.add("value1")
|
29
|
+
expect(@r.count("value1", 1)).to eq(2)
|
30
|
+
expect(@r.count("value2", 1)).to eq(0)
|
31
|
+
Timecop.travel(600) do
|
32
|
+
expect(@r.count("value1", 1)).to eq(0)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should be able to add to the count by more than 1" do
|
37
|
+
@r.add("value1", 3)
|
38
|
+
expect(@r.count("value1", 1)).to eq(3)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should be able to add to the count for a non-string subject" do
|
42
|
+
@r.add(123)
|
43
|
+
@r.add(123)
|
44
|
+
expect(@r.count(123, 1)).to eq(2)
|
45
|
+
expect(@r.count(124, 1)).to eq(0)
|
46
|
+
Timecop.travel(10) do
|
47
|
+
expect(@r.count(123, 1)).to eq(0)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should return counter value" do
|
52
|
+
counter_value = @r.add("value1")
|
53
|
+
expect(@r.count("value1", 1)).to eq(counter_value)
|
54
|
+
end
|
55
|
+
|
56
|
+
it "respond to exceeded? method correctly" do
|
57
|
+
5.times do
|
58
|
+
@r.add("value1")
|
59
|
+
end
|
60
|
+
|
61
|
+
expect(@r.exceeded?("value1", {:threshold => 10, :interval => 30})).to be false
|
62
|
+
expect(@r.within_bounds?("value1", {:threshold => 10, :interval => 30})).to be true
|
63
|
+
|
64
|
+
10.times do
|
65
|
+
@r.add("value1")
|
66
|
+
end
|
67
|
+
|
68
|
+
expect(@r.exceeded?("value1", {:threshold => 10, :interval => 30})).to be true
|
69
|
+
expect(@r.within_bounds?("value1", {:threshold => 10, :interval => 30})).to be false
|
70
|
+
end
|
71
|
+
|
72
|
+
it "accept a threshhold and a block that gets executed once it's below the threshold" do
|
73
|
+
expect(@r.count("key", 30)).to eq(0)
|
74
|
+
31.times do
|
75
|
+
@r.add("key")
|
76
|
+
end
|
77
|
+
expect(@r.count("key", 30)).to eq(31)
|
78
|
+
|
79
|
+
@value = nil
|
80
|
+
expect do
|
81
|
+
timeout(1) do
|
82
|
+
@r.exec_within_threshold("key", {:threshold => 30, :interval => 30}) do
|
83
|
+
@value = 2
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end.to raise_error(Timeout::Error)
|
87
|
+
expect(@value).to be nil
|
88
|
+
Timecop.travel(40) do
|
89
|
+
@r.exec_within_threshold("key", {:threshold => 30, :interval => 30}) do
|
90
|
+
@value = 1
|
91
|
+
end
|
92
|
+
end
|
93
|
+
expect(@value).to be 1
|
94
|
+
end
|
95
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# The generated `.rspec` file contains `--require spec_helper` which will cause this
|
4
|
+
# file to always be loaded, without a need to explicitly require it in any files.
|
5
|
+
#
|
6
|
+
# Given that it is always loaded, you are encouraged to keep this file as
|
7
|
+
# light-weight as possible. Requiring heavyweight dependencies from this file
|
8
|
+
# will add to the boot time of your test suite on EVERY test run, even for an
|
9
|
+
# individual file that may not need all of that loaded. Instead, make a
|
10
|
+
# separate helper file that requires this one and then use it only in the specs
|
11
|
+
# that actually need it.
|
12
|
+
#
|
13
|
+
# The `.rspec` file also contains a few flags that are not defaults but that
|
14
|
+
# users commonly want.
|
15
|
+
#
|
16
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
17
|
+
require 'coveralls'
|
18
|
+
Coveralls.wear!
|
19
|
+
require 'fakeredis'
|
20
|
+
require 'timecop'
|
21
|
+
require 'ratelimit'
|
22
|
+
|
23
|
+
RSpec.configure do |config|
|
24
|
+
# The settings below are suggested to provide a good initial experience
|
25
|
+
# with RSpec, but feel free to customize to your heart's content.
|
26
|
+
=begin
|
27
|
+
# These two settings work together to allow you to limit a spec run
|
28
|
+
# to individual examples or groups you care about by tagging them with
|
29
|
+
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
30
|
+
# get run.
|
31
|
+
config.filter_run :focus
|
32
|
+
config.run_all_when_everything_filtered = true
|
33
|
+
|
34
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
35
|
+
# file, and it's useful to allow more verbose output when running an
|
36
|
+
# individual spec file.
|
37
|
+
if config.files_to_run.one?
|
38
|
+
# Use the documentation formatter for detailed output,
|
39
|
+
# unless a formatter has already been configured
|
40
|
+
# (e.g. via a command-line flag).
|
41
|
+
config.default_formatter = 'doc'
|
42
|
+
end
|
43
|
+
|
44
|
+
# Print the 10 slowest examples and example groups at the
|
45
|
+
# end of the spec run, to help surface which specs are running
|
46
|
+
# particularly slow.
|
47
|
+
config.profile_examples = 10
|
48
|
+
|
49
|
+
# Run specs in random order to surface order dependencies. If you find an
|
50
|
+
# order dependency and want to debug it, you can fix the order by providing
|
51
|
+
# the seed, which is printed after each run.
|
52
|
+
# --seed 1234
|
53
|
+
config.order = :random
|
54
|
+
|
55
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
56
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
57
|
+
# test failures related to randomization by passing the same `--seed` value
|
58
|
+
# as the one that triggered the failure.
|
59
|
+
Kernel.srand config.seed
|
60
|
+
|
61
|
+
# rspec-expectations config goes here. You can use an alternate
|
62
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
63
|
+
# assertions if you prefer.
|
64
|
+
config.expect_with :rspec do |expectations|
|
65
|
+
# Enable only the newer, non-monkey-patching expect syntax.
|
66
|
+
# For more details, see:
|
67
|
+
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
|
68
|
+
expectations.syntax = :expect
|
69
|
+
end
|
70
|
+
|
71
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
72
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
73
|
+
config.mock_with :rspec do |mocks|
|
74
|
+
# Enable only the newer, non-monkey-patching expect syntax.
|
75
|
+
# For more details, see:
|
76
|
+
# - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
77
|
+
mocks.syntax = :expect
|
78
|
+
|
79
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
80
|
+
# a real object. This is generally recommended.
|
81
|
+
mocks.verify_partial_doubles = true
|
82
|
+
end
|
83
|
+
=end
|
84
|
+
end
|
metadata
CHANGED
@@ -1,38 +1,155 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ratelimit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
5
|
-
prerelease:
|
4
|
+
version: 1.0.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- E.J. Finneran
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2014-06-15 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: redis
|
16
|
-
requirement:
|
17
|
-
none: false
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: 2.0.0
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
|
-
version_requirements:
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 2.0.0
|
25
27
|
- !ruby/object:Gem::Dependency
|
26
28
|
name: redis-namespace
|
27
|
-
requirement:
|
28
|
-
none: false
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
29
30
|
requirements:
|
30
|
-
- -
|
31
|
+
- - ">="
|
31
32
|
- !ruby/object:Gem::Version
|
32
33
|
version: 1.0.0
|
33
34
|
type: :runtime
|
34
35
|
prerelease: false
|
35
|
-
version_requirements:
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.0.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.6'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.6'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: fakeredis
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: timecop
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rspec
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: yard
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: maruku
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: rdoc
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
36
153
|
description: This library uses Redis to track the number of actions for a given subject
|
37
154
|
over a flexible time frame.
|
38
155
|
email:
|
@@ -41,30 +158,47 @@ executables: []
|
|
41
158
|
extensions: []
|
42
159
|
extra_rdoc_files: []
|
43
160
|
files:
|
161
|
+
- ".document"
|
162
|
+
- ".gitignore"
|
163
|
+
- ".rspec"
|
164
|
+
- ".ruby-gemset"
|
165
|
+
- ".ruby-version"
|
166
|
+
- ".travis.yml"
|
167
|
+
- CHANGELOG
|
168
|
+
- Gemfile
|
169
|
+
- LICENSE.txt
|
170
|
+
- README.md
|
171
|
+
- Rakefile
|
44
172
|
- lib/ratelimit.rb
|
45
|
-
|
46
|
-
|
173
|
+
- lib/ratelimit/version.rb
|
174
|
+
- ratelimit.gemspec
|
175
|
+
- spec/ratelimit_spec.rb
|
176
|
+
- spec/spec_helper.rb
|
177
|
+
homepage: https://github.com/ejfinneran/ratelimit
|
178
|
+
licenses:
|
179
|
+
- MIT
|
180
|
+
metadata: {}
|
47
181
|
post_install_message:
|
48
182
|
rdoc_options: []
|
49
183
|
require_paths:
|
50
184
|
- lib
|
51
185
|
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
-
none: false
|
53
186
|
requirements:
|
54
|
-
- -
|
187
|
+
- - ">="
|
55
188
|
- !ruby/object:Gem::Version
|
56
189
|
version: '0'
|
57
190
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
-
none: false
|
59
191
|
requirements:
|
60
|
-
- -
|
192
|
+
- - ">="
|
61
193
|
- !ruby/object:Gem::Version
|
62
194
|
version: '0'
|
63
195
|
requirements: []
|
64
196
|
rubyforge_project:
|
65
|
-
rubygems_version:
|
197
|
+
rubygems_version: 2.2.2
|
66
198
|
signing_key:
|
67
|
-
specification_version:
|
199
|
+
specification_version: 4
|
68
200
|
summary: Rate limiting backed by redis
|
69
|
-
test_files:
|
201
|
+
test_files:
|
202
|
+
- spec/ratelimit_spec.rb
|
203
|
+
- spec/spec_helper.rb
|
70
204
|
has_rdoc:
|