railslove-rack-throttle 0.0.0 → 0.0.1

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.
data/README CHANGED
@@ -17,7 +17,7 @@ Difference
17
17
  There are two main differences:
18
18
 
19
19
  * Throttling per minute => use Rack::Throttle::PerMinute, :max => 60
20
- * On reject callback => use Rack::Throttle::PerMinute, :max => 60, :on_reject => Proc.new { puts "Go Away!" }
20
+ * On reject callback => use Rack::Throttle::PerMinute, :max => 60, :on_reject => Proc.new {|env| puts env.inspect }
21
21
 
22
22
  Features
23
23
  --------
@@ -111,7 +111,8 @@ Examples
111
111
  ### Using a callback when a visitor is rejected
112
112
 
113
113
  # Can be anything that responds to #call
114
- callback = Proc.new { puts "help!" }
114
+ # We also pass "env" as an attribute e.g. object.call(env)
115
+ callback = Proc.new {|env| puts "help!" }
115
116
  use Rack::Throttle::PerMinute, :max => 10, :on_reject => callback
116
117
 
117
118
  Throttling Strategies
data/README.md CHANGED
@@ -17,7 +17,7 @@ Difference
17
17
  There are two main differences:
18
18
 
19
19
  * Throttling per minute => use Rack::Throttle::PerMinute, :max => 60
20
- * On reject callback => use Rack::Throttle::PerMinute, :max => 60, :on_reject => Proc.new { puts "Go Away!" }
20
+ * On reject callback => use Rack::Throttle::PerMinute, :max => 60, :on_reject => Proc.new {|env| puts env.inspect }
21
21
 
22
22
  Features
23
23
  --------
@@ -111,7 +111,8 @@ Examples
111
111
  ### Using a callback when a visitor is rejected
112
112
 
113
113
  # Can be anything that responds to #call
114
- callback = Proc.new { puts "help!" }
114
+ # We also pass "env" as an attribute e.g. object.call(env)
115
+ callback = Proc.new {|env| puts "help!" }
115
116
  use Rack::Throttle::PerMinute, :max => 10, :on_reject => callback
116
117
 
117
118
  Throttling Strategies
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.0
1
+ 0.0.1
@@ -35,7 +35,7 @@ module Rack; module Throttle
35
35
  if allowed?(request)
36
36
  app.call(env)
37
37
  else
38
- call_on_reject
38
+ call_on_reject(env)
39
39
  rate_limit_exceeded
40
40
  end
41
41
  end
@@ -89,8 +89,8 @@ module Rack; module Throttle
89
89
  protected
90
90
 
91
91
  # Calls whatever object is passed with options[:on_reject] on initialize
92
- def call_on_reject
93
- @options[:on_reject].call if @options[:on_reject]
92
+ def call_on_reject(env)
93
+ @options[:on_reject].call(env) if @options[:on_reject]
94
94
  end
95
95
 
96
96
  ##
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{railslove-rack-throttle}
8
- s.version = "0.0.0"
8
+ s.version = "0.0.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Arto Bendiken", "Brendon Murphy", "reddavis"]
12
- s.date = %q{2010-07-14}
12
+ s.date = %q{2010-07-15}
13
13
  s.description = %q{Rack middleware for rate-limiting incoming HTTP requests.}
14
14
  s.email = %q{reddavis@gmail.com}
15
15
  s.extra_rdoc_files = [
data/spec/limiter_spec.rb CHANGED
@@ -50,15 +50,13 @@ describe Rack::Throttle::Limiter do
50
50
  end
51
51
 
52
52
  it "should call proc when false" do
53
- #proc = mock("test")
54
- #@app = Rack::Throttle::Limiter.new(@target_app, :on_reject => proc)
55
- #
56
- #app.should_receive(:allowed?).and_return(false)
57
- #proc.should_receive(:call).once
58
- #
59
- #get "/foo"
60
- #
61
- #@app = Rack::Throttle::Limiter.new(@target_app)
53
+ proc = mock("test")
54
+ @app = Rack::Throttle::Limiter.new(@target_app, :on_reject => proc)
55
+
56
+ app.stub!(:allowed?).and_return(false)
57
+ proc.should_receive(:call).once.with(an_instance_of(Hash))
58
+
59
+ get "/foo"
62
60
  end
63
61
  end
64
62
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 0
9
- version: 0.0.0
8
+ - 1
9
+ version: 0.0.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Arto Bendiken
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-07-14 00:00:00 +01:00
19
+ date: 2010-07-15 00:00:00 +01:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency