rate_limiter 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +9 -0
- data/Gemfile.lock +1 -1
- data/lib/rate_limiter/config.rb +2 -0
- data/lib/rate_limiter/controller.rb +3 -4
- data/lib/rate_limiter/model.rb +8 -8
- data/lib/rate_limiter/version.rb +1 -1
- data/lib/rate_limiter.rb +8 -10
- metadata +2 -2
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
## v0.0.5
|
2
|
+
|
3
|
+
* Enabling/Disabling for individual controllers actually works now.
|
4
|
+
|
5
|
+
## v0.0.4
|
6
|
+
|
7
|
+
* Added dummy Rails application for testing.
|
8
|
+
* Updated development dependencies.
|
9
|
+
|
1
10
|
## v0.0.3
|
2
11
|
|
3
12
|
* Added more if and unless conditions for rate limiting.
|
data/Gemfile.lock
CHANGED
data/lib/rate_limiter/config.rb
CHANGED
@@ -1,9 +1,8 @@
|
|
1
1
|
module RateLimiter
|
2
2
|
module Controller
|
3
3
|
def self.included(base)
|
4
|
-
base.before_filter :set_rate_limiter_source
|
5
|
-
base.before_filter :set_rate_limiter_controller_info
|
6
4
|
base.before_filter :set_rate_limiter_enabled_for_controller
|
5
|
+
base.before_filter :set_rate_limiter_source, :set_rate_limiter_controller_info
|
7
6
|
end
|
8
7
|
|
9
8
|
protected
|
@@ -23,11 +22,11 @@ module RateLimiter
|
|
23
22
|
private
|
24
23
|
|
25
24
|
def set_rate_limiter_source
|
26
|
-
::RateLimiter.source = user_for_rate_limiter
|
25
|
+
::RateLimiter.source = user_for_rate_limiter if rate_limiter_enabled_for_controller
|
27
26
|
end
|
28
27
|
|
29
28
|
def set_rate_limiter_controller_info
|
30
|
-
::RateLimiter.controller_info = info_for_rate_limiter
|
29
|
+
::RateLimiter.controller_info = info_for_rate_limiter if rate_limiter_enabled_for_controller
|
31
30
|
end
|
32
31
|
|
33
32
|
def set_rate_limiter_enabled_for_controller
|
data/lib/rate_limiter/model.rb
CHANGED
@@ -5,7 +5,7 @@ module RateLimiter
|
|
5
5
|
end
|
6
6
|
|
7
7
|
module ClassMethods
|
8
|
-
def rate_limit
|
8
|
+
def rate_limit(options = {})
|
9
9
|
send :include, InstanceMethods
|
10
10
|
|
11
11
|
class_attribute :rate_limit_on
|
@@ -23,15 +23,15 @@ module RateLimiter
|
|
23
23
|
class_attribute :rate_limit_enabled_for_model
|
24
24
|
self.rate_limit_enabled_for_model = true
|
25
25
|
|
26
|
-
|
27
|
-
|
28
|
-
end
|
26
|
+
self.before_create :check_rate_limit
|
27
|
+
end
|
29
28
|
|
30
|
-
|
31
|
-
|
32
|
-
|
29
|
+
def rate_limit_off
|
30
|
+
self.rate_limit_enabled_for_model = false
|
31
|
+
end
|
33
32
|
|
34
|
-
|
33
|
+
def rate_limit_on
|
34
|
+
self.rate_limit_enabled_for_model = true
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
data/lib/rate_limiter/version.rb
CHANGED
data/lib/rate_limiter.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'singleton'
|
2
|
-
|
3
1
|
require 'rate_limiter/config'
|
4
2
|
require 'rate_limiter/controller'
|
5
3
|
require 'rate_limiter/model'
|
@@ -14,11 +12,11 @@ module RateLimiter
|
|
14
12
|
end
|
15
13
|
|
16
14
|
def self.enabled_for_controller=(value)
|
17
|
-
|
15
|
+
rate_limiter_store[:request_enabled_for_controller] = value
|
18
16
|
end
|
19
17
|
|
20
18
|
def self.enabled_for_controller?
|
21
|
-
!!
|
19
|
+
!!rate_limiter_store[:request_enabled_for_controller]
|
22
20
|
end
|
23
21
|
|
24
22
|
def self.timestamp_field=(field_name)
|
@@ -30,25 +28,25 @@ module RateLimiter
|
|
30
28
|
end
|
31
29
|
|
32
30
|
def self.source=(value)
|
33
|
-
|
31
|
+
rate_limiter_store[:source] = value
|
34
32
|
end
|
35
33
|
|
36
34
|
def self.source
|
37
|
-
|
35
|
+
rate_limiter_store[:source]
|
38
36
|
end
|
39
37
|
|
40
38
|
def self.controller_info=(value)
|
41
|
-
|
39
|
+
rate_limiter_store[:controller_info] = value
|
42
40
|
end
|
43
41
|
|
44
42
|
def self.controller_info
|
45
|
-
|
43
|
+
rate_limiter_store[:controller_info]
|
46
44
|
end
|
47
45
|
|
48
46
|
private
|
49
47
|
|
50
|
-
def self.
|
51
|
-
Thread.current[:rate_limiter]
|
48
|
+
def self.rate_limiter_store
|
49
|
+
Thread.current[:rate_limiter] ||= { :request_enabled_for_controller => true }
|
52
50
|
end
|
53
51
|
|
54
52
|
def self.config
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rate_limiter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-12-
|
12
|
+
date: 2012-12-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: railties
|