rate_limiter 0.0.6 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +6 -0
  3. data/LICENSE.txt +20 -0
  4. data/README.md +18 -11
  5. data/lib/generators/rate_limiter/install_generator.rb +22 -0
  6. data/lib/generators/rate_limiter/templates/rate_limiter.rb +6 -0
  7. data/lib/rate_limiter.rb +51 -51
  8. data/lib/rate_limiter/config.rb +18 -3
  9. data/lib/rate_limiter/frameworks/rails.rb +3 -0
  10. data/lib/rate_limiter/frameworks/rails/controller.rb +69 -0
  11. data/lib/rate_limiter/model.rb +30 -48
  12. data/lib/rate_limiter/model_config.rb +34 -0
  13. data/lib/rate_limiter/request.rb +112 -0
  14. data/lib/rate_limiter/throttle.rb +79 -0
  15. data/lib/rate_limiter/validator.rb +29 -0
  16. data/lib/rate_limiter/version.rb +3 -1
  17. data/rate_limiter.gemspec +24 -18
  18. metadata +98 -183
  19. data/.gitignore +0 -11
  20. data/.rspec +0 -3
  21. data/.rvmrc +0 -80
  22. data/Gemfile +0 -3
  23. data/Gemfile.lock +0 -150
  24. data/Rakefile +0 -6
  25. data/lib/rate_limiter/controller.rb +0 -36
  26. data/spec/dummy/Rakefile +0 -7
  27. data/spec/dummy/app/assets/images/rails.png +0 -0
  28. data/spec/dummy/app/assets/javascripts/application.js +0 -15
  29. data/spec/dummy/app/assets/stylesheets/application.css +0 -13
  30. data/spec/dummy/app/controllers/application_controller.rb +0 -7
  31. data/spec/dummy/app/controllers/messages_controller.rb +0 -75
  32. data/spec/dummy/app/helpers/application_helper.rb +0 -2
  33. data/spec/dummy/app/mailers/.gitkeep +0 -0
  34. data/spec/dummy/app/models/message.rb +0 -5
  35. data/spec/dummy/app/views/layouts/application.html.erb +0 -15
  36. data/spec/dummy/app/views/messages/_form.html.erb +0 -22
  37. data/spec/dummy/app/views/messages/_message.html.erb +0 -8
  38. data/spec/dummy/app/views/messages/edit.html.erb +0 -3
  39. data/spec/dummy/app/views/messages/index.html.erb +0 -6
  40. data/spec/dummy/app/views/messages/new.html.erb +0 -3
  41. data/spec/dummy/app/views/messages/show.html.erb +0 -4
  42. data/spec/dummy/config.ru +0 -4
  43. data/spec/dummy/config/application.rb +0 -70
  44. data/spec/dummy/config/boot.rb +0 -11
  45. data/spec/dummy/config/database.yml +0 -25
  46. data/spec/dummy/config/environment.rb +0 -5
  47. data/spec/dummy/config/environments/development.rb +0 -37
  48. data/spec/dummy/config/environments/production.rb +0 -67
  49. data/spec/dummy/config/environments/test.rb +0 -37
  50. data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -7
  51. data/spec/dummy/config/initializers/inflections.rb +0 -15
  52. data/spec/dummy/config/initializers/mime_types.rb +0 -5
  53. data/spec/dummy/config/initializers/secret_token.rb +0 -7
  54. data/spec/dummy/config/initializers/session_store.rb +0 -8
  55. data/spec/dummy/config/initializers/wrap_parameters.rb +0 -14
  56. data/spec/dummy/config/locales/en.yml +0 -5
  57. data/spec/dummy/config/routes.rb +0 -5
  58. data/spec/dummy/db/migrate/20121213101512_create_messages.rb +0 -21
  59. data/spec/dummy/db/schema.rb +0 -33
  60. data/spec/dummy/db/seeds.rb +0 -7
  61. data/spec/dummy/lib/assets/.gitkeep +0 -0
  62. data/spec/dummy/lib/tasks/.gitkeep +0 -0
  63. data/spec/dummy/log/.gitkeep +0 -0
  64. data/spec/dummy/public/404.html +0 -26
  65. data/spec/dummy/public/422.html +0 -26
  66. data/spec/dummy/public/500.html +0 -25
  67. data/spec/dummy/public/favicon.ico +0 -0
  68. data/spec/dummy/script/rails +0 -6
  69. data/spec/rate_limiter/model_spec.rb +0 -20
  70. data/spec/rate_limiter_spec.rb +0 -10
  71. data/spec/spec_helper.rb +0 -30
data/.gitignore DELETED
@@ -1,11 +0,0 @@
1
- *.gem
2
- .bundle
3
- pkg/*
4
- .DS_Store
5
- ._*
6
- .idea/
7
- .redcar/
8
- spec/dummy/tmp/
9
- spec/dummy/db/*.sqlite3
10
- spec/dummy/log/*.log
11
-
data/.rspec DELETED
@@ -1,3 +0,0 @@
1
- --tty
2
- --colour
3
- --format p
data/.rvmrc DELETED
@@ -1,80 +0,0 @@
1
- #!/usr/bin/env bash
2
-
3
- # This is an RVM Project .rvmrc file, used to automatically load the ruby
4
- # development environment upon cd'ing into the directory
5
-
6
- # First we specify our desired <ruby>[@<gemset>], the @gemset name is optional.
7
- environment_id="ruby-1.9.3-p327@rate_limiter"
8
-
9
- #
10
- # Uncomment the following lines if you want to verify rvm version per project
11
- #
12
- # rvmrc_rvm_version="1.10.2" # 1.10.1 seams as a safe start
13
- # eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
14
- # echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
15
- # return 1
16
- # }
17
- #
18
-
19
- #
20
- # Uncomment following line if you want options to be set only for given project.
21
- #
22
- # PROJECT_JRUBY_OPTS=( --1.9 )
23
- #
24
- # The variable PROJECT_JRUBY_OPTS requires the following to be run in shell:
25
- #
26
- # chmod +x ${rvm_path}/hooks/after_use_jruby_opts
27
- #
28
-
29
- #
30
- # First we attempt to load the desired environment directly from the environment
31
- # file. This is very fast and efficient compared to running through the entire
32
- # CLI and selector. If you want feedback on which environment was used then
33
- # insert the word 'use' after --create as this triggers verbose mode.
34
- #
35
- if [[ -d "${rvm_path:-$HOME/.rvm}/environments" \
36
- && -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
37
- then
38
- \. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
39
-
40
- if [[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]]
41
- then
42
- . "${rvm_path:-$HOME/.rvm}/hooks/after_use"
43
- fi
44
- else
45
- # If the environment file has not yet been created, use the RVM CLI to select.
46
- if ! rvm --create "$environment_id"
47
- then
48
- echo "Failed to create RVM environment '${environment_id}'."
49
- return 1
50
- fi
51
- fi
52
-
53
- #
54
- # If you use an RVM gemset file to install a list of gems (*.gems), you can have
55
- # it be automatically loaded. Uncomment the following and adjust the filename if
56
- # necessary.
57
- #
58
- # filename=".gems"
59
- # if [[ -s "$filename" ]]
60
- # then
61
- # rvm gemset import "$filename" | grep -v already | grep -v listed | grep -v complete | sed '/^$/d'
62
- # fi
63
-
64
- # If you use bundler, this might be useful to you:
65
- # if [[ -s Gemfile ]] && ! command -v bundle >/dev/null
66
- # then
67
- # printf "%b" "The rubygem 'bundler' is not installed. Installing it now.\n"
68
- # gem install bundler
69
- # fi
70
- # if [[ -s Gemfile ]] && command -v bundle
71
- # then
72
- # bundle install
73
- # fi
74
-
75
- if [[ $- == *i* ]] # check for interactive shells
76
- then
77
- echo "Using: $(tput setaf 2)$GEM_HOME$(tput sgr0)" # show the user the ruby and gemset they are using in green
78
- else
79
- echo "Using: $GEM_HOME" # don't use colors in interactive shells
80
- fi
data/Gemfile DELETED
@@ -1,3 +0,0 @@
1
- source :rubygems
2
-
3
- gemspec
data/Gemfile.lock DELETED
@@ -1,150 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- rate_limiter (0.0.5)
5
- activerecord (>= 3.2)
6
- railties (>= 3.2)
7
-
8
- GEM
9
- remote: http://rubygems.org/
10
- specs:
11
- actionmailer (3.2.9)
12
- actionpack (= 3.2.9)
13
- mail (~> 2.4.4)
14
- actionpack (3.2.9)
15
- activemodel (= 3.2.9)
16
- activesupport (= 3.2.9)
17
- builder (~> 3.0.0)
18
- erubis (~> 2.7.0)
19
- journey (~> 1.0.4)
20
- rack (~> 1.4.0)
21
- rack-cache (~> 1.2)
22
- rack-test (~> 0.6.1)
23
- sprockets (~> 2.2.1)
24
- activemodel (3.2.9)
25
- activesupport (= 3.2.9)
26
- builder (~> 3.0.0)
27
- activerecord (3.2.9)
28
- activemodel (= 3.2.9)
29
- activesupport (= 3.2.9)
30
- arel (~> 3.0.2)
31
- tzinfo (~> 0.3.29)
32
- activeresource (3.2.9)
33
- activemodel (= 3.2.9)
34
- activesupport (= 3.2.9)
35
- activesupport (3.2.9)
36
- i18n (~> 0.6)
37
- multi_json (~> 1.0)
38
- addressable (2.3.2)
39
- arel (3.0.2)
40
- bourne (1.1.2)
41
- mocha (= 0.10.5)
42
- builder (3.0.4)
43
- capybara (2.0.1)
44
- mime-types (>= 1.16)
45
- nokogiri (>= 1.3.3)
46
- rack (>= 1.0.0)
47
- rack-test (>= 0.5.4)
48
- selenium-webdriver (~> 2.0)
49
- xpath (~> 1.0.0)
50
- childprocess (0.3.6)
51
- ffi (~> 1.0, >= 1.0.6)
52
- database_cleaner (0.9.1)
53
- diff-lcs (1.1.3)
54
- erubis (2.7.0)
55
- ffi (1.2.0)
56
- hike (1.2.1)
57
- i18n (0.6.1)
58
- journey (1.0.4)
59
- jquery-rails (2.1.4)
60
- railties (>= 3.0, < 5.0)
61
- thor (>= 0.14, < 2.0)
62
- json (1.7.5)
63
- libwebsocket (0.1.7.1)
64
- addressable
65
- websocket
66
- mail (2.4.4)
67
- i18n (>= 0.4.0)
68
- mime-types (~> 1.16)
69
- treetop (~> 1.4.8)
70
- metaclass (0.0.1)
71
- mime-types (1.19)
72
- mocha (0.10.5)
73
- metaclass (~> 0.0.1)
74
- multi_json (1.5.0)
75
- nokogiri (1.5.5)
76
- polyglot (0.3.3)
77
- rack (1.4.1)
78
- rack-cache (1.2)
79
- rack (>= 0.4)
80
- rack-ssl (1.3.2)
81
- rack
82
- rack-test (0.6.2)
83
- rack (>= 1.0)
84
- rails (3.2.9)
85
- actionmailer (= 3.2.9)
86
- actionpack (= 3.2.9)
87
- activerecord (= 3.2.9)
88
- activeresource (= 3.2.9)
89
- activesupport (= 3.2.9)
90
- bundler (~> 1.0)
91
- railties (= 3.2.9)
92
- railties (3.2.9)
93
- actionpack (= 3.2.9)
94
- activesupport (= 3.2.9)
95
- rack-ssl (~> 1.3.2)
96
- rake (>= 0.8.7)
97
- rdoc (~> 3.4)
98
- thor (>= 0.14.6, < 2.0)
99
- rake (10.0.2)
100
- rdoc (3.12)
101
- json (~> 1.4)
102
- rspec-core (2.12.1)
103
- rspec-expectations (2.12.0)
104
- diff-lcs (~> 1.1.3)
105
- rspec-mocks (2.12.0)
106
- rspec-rails (2.12.0)
107
- actionpack (>= 3.0)
108
- activesupport (>= 3.0)
109
- railties (>= 3.0)
110
- rspec-core (~> 2.12.0)
111
- rspec-expectations (~> 2.12.0)
112
- rspec-mocks (~> 2.12.0)
113
- rubyzip (0.9.9)
114
- selenium-webdriver (2.27.2)
115
- childprocess (>= 0.2.5)
116
- libwebsocket (~> 0.1.3)
117
- multi_json (~> 1.0)
118
- rubyzip
119
- shoulda-matchers (1.4.2)
120
- activesupport (>= 3.0.0)
121
- bourne (~> 1.1.2)
122
- sprockets (2.2.2)
123
- hike (~> 1.2)
124
- multi_json (~> 1.0)
125
- rack (~> 1.0)
126
- tilt (~> 1.1, != 1.3.0)
127
- sqlite3 (1.3.6)
128
- thor (0.16.0)
129
- tilt (1.3.3)
130
- treetop (1.4.12)
131
- polyglot
132
- polyglot (>= 0.3.1)
133
- tzinfo (0.3.35)
134
- websocket (1.0.4)
135
- xpath (1.0.0)
136
- nokogiri (~> 1.3)
137
-
138
- PLATFORMS
139
- ruby
140
-
141
- DEPENDENCIES
142
- capybara
143
- database_cleaner
144
- jquery-rails
145
- rails (>= 3.2)
146
- rake
147
- rate_limiter!
148
- rspec-rails
149
- shoulda-matchers
150
- sqlite3
data/Rakefile DELETED
@@ -1,6 +0,0 @@
1
- require 'bundler/gem_tasks'
2
- require 'rspec/core/rake_task'
3
-
4
- RSpec::Core::RakeTask.new(:spec)
5
-
6
- task :default => :spec
@@ -1,36 +0,0 @@
1
- module RateLimiter
2
- module Controller
3
- def self.included(base)
4
- base.before_filter :set_rate_limiter_enabled_for_controller
5
- base.before_filter :set_rate_limiter_source, :set_rate_limiter_controller_info
6
- end
7
-
8
- protected
9
-
10
- def user_for_rate_limiter
11
- current_user rescue nil
12
- end
13
-
14
- def info_for_rate_limiter
15
- {}
16
- end
17
-
18
- def rate_limiter_enabled_for_controller
19
- true
20
- end
21
-
22
- private
23
-
24
- def set_rate_limiter_source
25
- ::RateLimiter.source = user_for_rate_limiter if rate_limiter_enabled_for_controller
26
- end
27
-
28
- def set_rate_limiter_controller_info
29
- ::RateLimiter.controller_info = info_for_rate_limiter if rate_limiter_enabled_for_controller
30
- end
31
-
32
- def set_rate_limiter_enabled_for_controller
33
- ::RateLimiter.enabled_for_controller = rate_limiter_enabled_for_controller
34
- end
35
- end
36
- end
data/spec/dummy/Rakefile DELETED
@@ -1,7 +0,0 @@
1
- #!/usr/bin/env rake
2
- # Add your own tasks in files placed in lib/tasks ending in .rake,
3
- # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
4
-
5
- require File.expand_path('../config/application', __FILE__)
6
-
7
- Dummy::Application.load_tasks
Binary file
@@ -1,15 +0,0 @@
1
- // This is a manifest file that'll be compiled into application.js, which will include all the files
2
- // listed below.
3
- //
4
- // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
- // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
- //
7
- // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
- // the compiled file.
9
- //
10
- // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
11
- // GO AFTER THE REQUIRES BELOW.
12
- //
13
- //= require jquery
14
- //= require jquery_ujs
15
- //= require_tree .
@@ -1,13 +0,0 @@
1
- /*
2
- * This is a manifest file that'll be compiled into application.css, which will include all the files
3
- * listed below.
4
- *
5
- * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
- * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
- *
8
- * You're free to add application-wide styles to this file and they'll appear at the top of the
9
- * compiled file, but it's generally better to create a new file per style scope.
10
- *
11
- *= require_self
12
- *= require_tree .
13
- */
@@ -1,7 +0,0 @@
1
- class ApplicationController < ActionController::Base
2
- protect_from_forgery
3
-
4
- def current_user
5
- 'Test User'
6
- end
7
- end
@@ -1,75 +0,0 @@
1
- class MessagesController < ApplicationController
2
- def index
3
- @messages = Message.all
4
- end
5
-
6
- def show
7
- @message = Message.where(:id => params[:id]).first
8
-
9
- if @message.nil?
10
- flash[:error] = 'Could not find the specified message.'
11
-
12
- redirect_to messages_url
13
- end
14
- end
15
-
16
- def new
17
- @message = Message.new
18
- end
19
-
20
- def create
21
- @message = Message.new(params[:message])
22
-
23
- @message.ip_address = request.remote_ip
24
-
25
- if @message.save
26
- flash[:success] = 'Message has been saved.'
27
-
28
- redirect_to messages_url
29
- else
30
- render 'new'
31
- end
32
- end
33
-
34
- def edit
35
- @message = Message.where(:id => params[:id]).first
36
-
37
- if @message.nil?
38
- flash[:error] = 'Could not find the specified message.'
39
-
40
- redirect_to messages_url
41
- end
42
- end
43
-
44
- def update
45
- @message = Message.where(:id => params[:id]).first
46
-
47
- if @message.nil?
48
- flash[:error] = 'Could not find the specified message.'
49
-
50
- redirect_to messages_url
51
- end
52
-
53
- if @message.update_attributes(params[:message])
54
- flash[:success] = 'Message has been updated.'
55
-
56
- redirect_to messages_url
57
- else
58
- render 'edit'
59
- end
60
- end
61
-
62
- def destroy
63
- @message = Message.where(:id => params[:id]).first
64
-
65
- if @message.nil?
66
- flash[:error] = 'Could not find the specified message.'
67
-
68
- redirect_to messages_url
69
- end
70
-
71
- @message.destroy
72
-
73
- redirect_to messages_url
74
- end
75
- end
@@ -1,2 +0,0 @@
1
- module ApplicationHelper
2
- end
File without changes
@@ -1,5 +0,0 @@
1
- class Message < ActiveRecord::Base
2
- attr_accessible :first_name, :last_name, :subject, :body, :ip_address
3
-
4
- rate_limit :on => :ip_address, :interval => 1.minute
5
- end
@@ -1,15 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title>Dummy</title>
5
- <%= stylesheet_link_tag "application", :media => "all" %>
6
- <%= javascript_include_tag "application" %>
7
- <%= csrf_meta_tags %>
8
- </head>
9
- <body>
10
- <div id="nav">
11
- <%= link_to 'Home', root_path %> | <%= link_to 'New Message', new_message_path %>
12
- </div>
13
- <%= yield %>
14
- </body>
15
- </html>