grape-throttler 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c02d5c5ef081337c20539acf09bafd5c9ae35fedeeb16a92c38b16e5839fed04
4
- data.tar.gz: b49635981a48db4d77ffb3ce56e539b1b33aa42727f931e20e5324dea0320645
3
+ metadata.gz: 9d403d14a732f3f185b5a9d175165dceb3162d8dc263a4e95f450d1bfb9f0e88
4
+ data.tar.gz: 66e8937eb07b2e2c09762030803eabdcc68c13b376aac3fc7ee1fc02496984c9
5
5
  SHA512:
6
- metadata.gz: bbcca0e55d60925b0afb472459c88580e8dfe214c27059fa26e92a825b5f72ac3d6e5225d00ed8e38e3ca0f439f99d2334a0d2631907763453ee783d1c6f4fa3
7
- data.tar.gz: 40644a93838ebe1e019bbfee16cf11606b4bbc375f569c554d5ed52ee99689c2e9da100ec69ad85799caf95180151c75d76ae96c9e0d1b25aef25065102eab35
6
+ metadata.gz: 633574dd952dfaf7ffe0deadc2640a1b07b7ee540b46962f21306b910f5d9eb4453169b72039cffdf4a1c51a7a3aa2074aca4590d0bf1baef13f7ed3fd3e0936
7
+ data.tar.gz: e7770fb63e7aae40dacf0e4705430394e4ef5dfa46c07c6e6ee92225614a51bb992938232bd64800499cd304b5998848498ef765e36317c218515f48d464147b
@@ -1,19 +1,19 @@
1
1
  speedups:
2
- rescue_vs_respond_to: false
3
- module_eval: true
4
- shuffle_first_vs_sample: true
5
- for_loop_vs_each: true
2
+ block_vs_symbol_to_proc: true
6
3
  each_with_index_vs_while: false
7
- map_flatten_vs_flat_map: true
8
- reverse_each_vs_reverse_each: true
9
- select_first_vs_detect: true
10
- sort_vs_sort_by: true
11
4
  fetch_with_argument_vs_block: true
12
- keys_each_vs_each_key: true
5
+ for_loop_vs_each: true
6
+ getter_vs_attr_reader: true
7
+ gsub_vs_tr: true
13
8
  hash_merge_bang_vs_hash_brackets: true
14
- block_vs_symbol_to_proc: true
9
+ keys_each_vs_each_key: true
10
+ map_flatten_vs_flat_map: true
11
+ module_eval: true
15
12
  proc_call_vs_yield: true
16
- gsub_vs_tr: true
13
+ rescue_vs_respond_to: true
14
+ reverse_each_vs_reverse_each: true
15
+ select_first_vs_detect: true
17
16
  select_last_vs_reverse_detect: true
18
- getter_vs_attr_reader: true
19
17
  setter_vs_attr_writer: true
18
+ shuffle_first_vs_sample: true
19
+ sort_vs_sort_by: true
data/.gitignore CHANGED
@@ -1,13 +1,11 @@
1
1
  /.bundle/
2
2
  /.yardoc
3
- /Gemfile.lock
4
3
  /_yardoc/
5
4
  /coverage/
6
5
  /doc/
7
6
  /pkg/
8
7
  /spec/reports/
9
8
  /tmp/
10
- /.irbrc_history
11
9
 
12
10
  # rspec failure tracking
13
11
  .rspec_status
@@ -1,39 +1,33 @@
1
+ require:
2
+ - rubocop-performance
3
+ - rubocop-rspec
1
4
  AllCops:
5
+ TargetRubyVersion: 2.6
2
6
  DisplayCopNames: true
3
7
  DisplayStyleGuide: true
4
- TargetRubyVersion: 2.5
8
+ Layout/EmptyLinesAroundBlockBody:
5
9
  Exclude:
6
- - 'lib/**/**/templates/*'
7
10
  - 'spec/**/**/*'
8
11
  Layout/EmptyLinesAroundClassBody:
9
- Enabled: false
12
+ EnforcedStyle: empty_lines_except_namespace
10
13
  Layout/EmptyLinesAroundModuleBody:
11
- Enabled: false
12
- LineLength:
14
+ EnforcedStyle: empty_lines_except_namespace
15
+ Metrics/BlockLength:
16
+ Exclude:
17
+ - 'spec/**/**/*'
18
+ - '*.gemspec'
19
+ Metrics/LineLength:
13
20
  Max: 100
14
- Lint/AssignmentInCondition:
15
- Enabled: false
16
- Lint/RescueException:
17
- Enabled: false
18
- Lint/ScriptPermission:
19
- Enabled: false
20
- Metrics/AbcSize:
21
- Enabled: false
22
- Metrics/CyclomaticComplexity:
23
- Enabled: false
24
- Metrics/MethodLength:
25
- Enabled: false
26
- Metrics/PerceivedComplexity:
27
- Enabled: false
28
21
  Naming/FileName:
29
22
  Enabled: false
30
- Style/BracesAroundHashParameters:
23
+ RSpec/ExampleLength:
24
+ Enabled: false
25
+ RSpec/FilePath:
26
+ Exclude:
27
+ - 'spec/grape-throttler/version_spec.rb'
28
+ RSpec/MultipleExpectations:
31
29
  Enabled: false
32
30
  Style/Documentation:
33
31
  Enabled: false
34
32
  Style/ExpandPathArguments:
35
33
  Enabled: false
36
- Style/RescueModifier:
37
- Enabled: false
38
- Style/RescueStandardError:
39
- Enabled: false
@@ -1,5 +1,24 @@
1
1
  sudo: false
2
2
  language: ruby
3
+ cache: bundler
3
4
  rvm:
4
- - 2.5.1
5
- before_install: gem install bundler
5
+ - 2.5
6
+ - 2.6
7
+ - ruby-head
8
+ matrix:
9
+ fast_finish: true
10
+ allow_failures:
11
+ - rvm: ruby-head
12
+ before_install:
13
+ - gem update --system
14
+ - gem install bundler
15
+ install:
16
+ - bundle install --jobs=3 --retry=3
17
+ script:
18
+ - bundle exec rspec
19
+ - bundle exec rubocop
20
+ - bundle exec fasterer
21
+ notifications:
22
+ email: false
23
+ slack:
24
+ secure: WN6Tc8kREPwVy7a+Pk1TpzKkzM8Hk++8Z8znAS51mkpvkv8g95HO9TysTZtQ+gv05L4l9V9tJsjVF2vCvJgrWQ84ilhpgBG62X+L2E/2SPB3TX0Hxh+VInCkmsg1h/FsnoZ1S9H4WjW6jbunCWl+ecytCJXNFvKtkmsbUAIVZY2jji6oKacsQZMeL+BvsKAnny7/1JJ3sSEuGZ4LXeQ1TL+mI74awmeJIuGWJfwNH6fW/z6sN4f/25ZNtiLEMZ+0rzzE7mO4k3GBv+tPPwqL1547/2KTEwHCSmPDHjpmzdA0yQ/razrA4n/Iqb5vS0ZCS6WYg6udiAh5aWwUg+g4VAzMegTqw0kGWpnTHNTuMzRGh1uKTXF5MH4T+a1FGOxnrFkZUZhCJPa2+NTbuHHxl6pycFxA+D7sGvEwaEbRgJ26y0IGk9ZnhJAhmtEddsCsdcPE4pb+10+ppbOZI1fW56UT3/f6l75Zj2QclmE2EjEi4+MqgLX8FJvT5iHhsBH7/MFNlOGftH/l2iiRFu9MmFC/BroAOF541DSP/n/Eocu7f2tiHV3Km9beHOWwYLL7nGhPhp2XlzaYA2eTQtzF3foswL440OO0PMfmmT2AbjK8uagvPPQkPFv40L40KLOnsKo+/tli8IjSqWDdwKrR69X0EmAflpu8UBzez8pCe9A=
@@ -0,0 +1,17 @@
1
+ # Changelog
2
+ All notable changes to this project will be documented in this file.
3
+
4
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
+
7
+ ## [Unreleased]
8
+
9
+ ## [1.1.0] - 2019-11-25
10
+ ### Added
11
+ - Added CHANGELOG.md
12
+ ### Changed
13
+ - Refactor code to clean up lint errors
14
+
15
+ ## [1.0.1] - 2019-11-25
16
+ ### NOTE
17
+ - Previous version without CHANGELOG.md
@@ -1,13 +1,74 @@
1
- # Contributor Code of Conduct
1
+ # Contributor Covenant Code of Conduct
2
2
 
3
- As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
3
+ ## Our Pledge
4
4
 
5
- We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
6
11
 
7
- Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
12
+ ## Our Standards
8
13
 
9
- Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
10
16
 
11
- Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
12
22
 
13
- This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at j.gomez@drexed.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile CHANGED
@@ -2,7 +2,5 @@
2
2
 
3
3
  source 'https://rubygems.org'
4
4
 
5
- git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
-
7
- # Specify your gem's dependencies in hacklines_extractors.gemspec
5
+ # Specify your gem's dependencies in grape-throttler.gemspec
8
6
  gemspec
@@ -0,0 +1,116 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ grape-throttler (1.1.0)
5
+ grape (>= 0.16.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ activesupport (6.0.1)
11
+ concurrent-ruby (~> 1.0, >= 1.0.2)
12
+ i18n (>= 0.7, < 2)
13
+ minitest (~> 5.1)
14
+ tzinfo (~> 1.1)
15
+ zeitwerk (~> 2.2)
16
+ ast (2.4.0)
17
+ axiom-types (0.1.1)
18
+ descendants_tracker (~> 0.0.4)
19
+ ice_nine (~> 0.11.0)
20
+ thread_safe (~> 0.3, >= 0.3.1)
21
+ builder (3.2.3)
22
+ coercible (1.0.0)
23
+ descendants_tracker (~> 0.0.1)
24
+ colorize (0.8.1)
25
+ concurrent-ruby (1.1.5)
26
+ descendants_tracker (0.0.4)
27
+ thread_safe (~> 0.3, >= 0.3.1)
28
+ diff-lcs (1.3)
29
+ equalizer (0.0.11)
30
+ fakeredis (0.7.0)
31
+ redis (>= 3.2, < 5.0)
32
+ fasterer (0.8.1)
33
+ colorize (~> 0.7)
34
+ ruby_parser (>= 3.14.1)
35
+ grape (1.2.4)
36
+ activesupport
37
+ builder
38
+ mustermann-grape (~> 1.0.0)
39
+ rack (>= 1.3.0)
40
+ rack-accept
41
+ virtus (>= 1.0.0)
42
+ i18n (1.7.0)
43
+ concurrent-ruby (~> 1.0)
44
+ ice_nine (0.11.2)
45
+ jaro_winkler (1.5.4)
46
+ minitest (5.13.0)
47
+ mustermann (1.0.3)
48
+ mustermann-grape (1.0.0)
49
+ mustermann (~> 1.0.0)
50
+ parallel (1.19.1)
51
+ parser (2.6.5.0)
52
+ ast (~> 2.4.0)
53
+ rack (2.0.7)
54
+ rack-accept (0.4.5)
55
+ rack (>= 0.4)
56
+ rack-test (1.1.0)
57
+ rack (>= 1.0, < 3)
58
+ rainbow (3.0.0)
59
+ rake (13.0.1)
60
+ redis (4.1.3)
61
+ rspec (3.9.0)
62
+ rspec-core (~> 3.9.0)
63
+ rspec-expectations (~> 3.9.0)
64
+ rspec-mocks (~> 3.9.0)
65
+ rspec-core (3.9.0)
66
+ rspec-support (~> 3.9.0)
67
+ rspec-expectations (3.9.0)
68
+ diff-lcs (>= 1.2.0, < 2.0)
69
+ rspec-support (~> 3.9.0)
70
+ rspec-mocks (3.9.0)
71
+ diff-lcs (>= 1.2.0, < 2.0)
72
+ rspec-support (~> 3.9.0)
73
+ rspec-support (3.9.0)
74
+ rubocop (0.76.0)
75
+ jaro_winkler (~> 1.5.1)
76
+ parallel (~> 1.10)
77
+ parser (>= 2.6)
78
+ rainbow (>= 2.2.2, < 4.0)
79
+ ruby-progressbar (~> 1.7)
80
+ unicode-display_width (>= 1.4.0, < 1.7)
81
+ rubocop-performance (1.5.1)
82
+ rubocop (>= 0.71.0)
83
+ rubocop-rspec (1.37.0)
84
+ rubocop (>= 0.68.1)
85
+ ruby-progressbar (1.10.1)
86
+ ruby_parser (3.14.1)
87
+ sexp_processor (~> 4.9)
88
+ sexp_processor (4.13.0)
89
+ thread_safe (0.3.6)
90
+ tzinfo (1.2.5)
91
+ thread_safe (~> 0.1)
92
+ unicode-display_width (1.6.0)
93
+ virtus (1.0.5)
94
+ axiom-types (~> 0.1)
95
+ coercible (~> 1.0)
96
+ descendants_tracker (~> 0.0, >= 0.0.3)
97
+ equalizer (~> 0.0, >= 0.0.9)
98
+ zeitwerk (2.2.1)
99
+
100
+ PLATFORMS
101
+ ruby
102
+
103
+ DEPENDENCIES
104
+ bundler
105
+ fakeredis
106
+ fasterer
107
+ grape-throttler!
108
+ rack-test
109
+ rake
110
+ rspec
111
+ rubocop
112
+ rubocop-performance
113
+ rubocop-rspec
114
+
115
+ BUNDLED WITH
116
+ 1.17.3
data/README.md CHANGED
@@ -115,12 +115,20 @@ class API < GrapeThrottler::API
115
115
  end
116
116
  ```
117
117
 
118
+ ## Development
119
+
120
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
121
+
122
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
123
+
118
124
  ## Contributing
119
125
 
120
- Your contribution is welcome.
126
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/grape-throttler. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
127
+
128
+ ## License
129
+
130
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
131
+
132
+ ## Code of Conduct
121
133
 
122
- 1. Fork it
123
- 2. Create your feature branch (`git checkout -b my-new-feature`)
124
- 3. Commit your changes (`git commit -am 'Added some feature'`)
125
- 4. Push to the branch (`git push origin my-new-feature`)
126
- 5. Create new Pull Request
134
+ Everyone interacting in the Lite::Ruby project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/grape-throttler/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1 @@
1
+ theme: jekyll-theme-leap-day
@@ -8,8 +8,8 @@ require 'grape-throttler'
8
8
  # with your gem easier. You can also use a different console, if you like.
9
9
 
10
10
  # (If you use this, don't forget to add pry to your Gemfile!)
11
- # require 'pry'
11
+ # require "pry"
12
12
  # Pry.start
13
13
 
14
14
  require 'irb'
15
- IRB.start
15
+ IRB.start(__FILE__)
data/bin/setup CHANGED
@@ -1,6 +1,7 @@
1
- #!/bin/bash
1
+ #!/usr/bin/env bash
2
2
  set -euo pipefail
3
3
  IFS=$'\n\t'
4
+ set -vx
4
5
 
5
6
  bundle install
6
7
 
@@ -10,25 +10,42 @@ Gem::Specification.new do |spec|
10
10
  spec.authors = ['Juan Gomez']
11
11
  spec.email = ['j.gomez@drexed.com']
12
12
 
13
- spec.summary = 'Gem for throttling grape requests.'
14
- spec.description = 'A middleware for Grape to add endpoint-specific throttling.'
13
+ spec.summary = 'Middleware for Grape to add endpoint-specific throttling.'
15
14
  spec.homepage = 'http://drexed.github.io/grape-throttler'
16
15
  spec.license = 'MIT'
17
16
 
18
- spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata.merge(
21
+ 'allowed_push_host' => 'https://rubygems.org',
22
+ 'changelog_uri' => 'https://github.com/drexed/grape-throttler/blob/master/CHANGELOG.md',
23
+ 'homepage_uri' => spec.homepage,
24
+ 'source_code_uri' => 'https://github.com/drexed/grape-throttler'
25
+ )
26
+ else
27
+ raise 'RubyGems 2.0 or newer is required to protect against ' \
28
+ 'public gem pushes.'
29
+ end
30
+
31
+ # Specify which files should be added to the gem when it is released.
32
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
33
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
34
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
35
+ end
19
36
  spec.bindir = 'exe'
20
37
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
38
  spec.require_paths = %w[lib]
22
39
 
23
40
  spec.add_runtime_dependency 'grape', '>= 0.16.0'
24
- spec.add_runtime_dependency 'rails'
25
41
 
26
42
  spec.add_development_dependency 'bundler'
27
43
  spec.add_development_dependency 'fakeredis'
28
44
  spec.add_development_dependency 'fasterer'
29
45
  spec.add_development_dependency 'rack-test'
30
46
  spec.add_development_dependency 'rake'
31
- spec.add_development_dependency 'reek'
32
47
  spec.add_development_dependency 'rspec'
33
48
  spec.add_development_dependency 'rubocop'
49
+ spec.add_development_dependency 'rubocop-performance'
50
+ spec.add_development_dependency 'rubocop-rspec'
34
51
  end
@@ -6,6 +6,8 @@ module GrapeThrottler
6
6
 
7
7
  COUNTER_START ||= 0
8
8
 
9
+ # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
10
+ # rubocop:disable Metrics/PerceivedComplexity, Lint/AssignmentInCondition
9
11
  def before
10
12
  endpoint = env['api.endpoint']
11
13
  logger = options[:logger] || Logger.new(STDOUT)
@@ -32,14 +34,16 @@ module GrapeThrottler
32
34
  endpoint.error!('Too Many Requests', 429)
33
35
  else
34
36
  redis.multi do
35
- redis.set(rate_key, COUNTER_START, { nx: true, ex: period.to_i })
37
+ redis.set(rate_key, COUNTER_START, nx: true, ex: period.to_i)
36
38
  redis.incr(rate_key)
37
39
  end
38
40
  end
39
- rescue Exception => e
41
+ rescue StandardError => e
40
42
  logger.warn(e.message)
41
43
  end
42
44
  end
45
+ # rubocop:enable Metrics/PerceivedComplexity, Lint/AssignmentInCondition
46
+ # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
43
47
 
44
48
  private
45
49
 
@@ -49,6 +53,7 @@ module GrapeThrottler
49
53
  raise ArgumentError, 'Please set a period and limit (see documentation)'
50
54
  end
51
55
 
56
+ # rubocop:disable Lint/AssignmentInCondition
52
57
  def find_limit_and_period(throttle_options)
53
58
  if limit = throttle_options[:hourly]
54
59
  period = 1.hour
@@ -62,6 +67,7 @@ module GrapeThrottler
62
67
 
63
68
  [limit, period]
64
69
  end
70
+ # rubocop:enable Lint/AssignmentInCondition
65
71
 
66
72
  def find_user_value(options)
67
73
  user_key = options[:user_key]
@@ -71,8 +77,8 @@ module GrapeThrottler
71
77
  end
72
78
 
73
79
  def generate_rate_key(endpoint, user_value)
74
- epoint = endpoint.routes.first
75
- "#{epoint.request_method}:#{epoint.path}:#{user_value}"
80
+ endpoint_route = endpoint.routes.first
81
+ "#{endpoint_route.request_method}:#{endpoint_route.path}:#{user_value}"
76
82
  end
77
83
 
78
84
  end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GrapeThrottler
4
- VERSION ||= '1.0.1'
4
+
5
+ VERSION ||= '1.1.0'
6
+
5
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grape-throttler
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juan Gomez
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-09-18 00:00:00.000000000 Z
11
+ date: 2019-11-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: grape
@@ -25,13 +25,13 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: 0.16.0
27
27
  - !ruby/object:Gem::Dependency
28
- name: rails
28
+ name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
- type: :runtime
34
+ type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
@@ -39,7 +39,7 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: bundler
42
+ name: fakeredis
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">="
@@ -53,7 +53,7 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: fakeredis
56
+ name: fasterer
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - ">="
@@ -67,7 +67,7 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: fasterer
70
+ name: rack-test
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - ">="
@@ -81,7 +81,7 @@ dependencies:
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
- name: rack-test
84
+ name: rake
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - ">="
@@ -95,7 +95,7 @@ dependencies:
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
- name: rake
98
+ name: rspec
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - ">="
@@ -109,7 +109,7 @@ dependencies:
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  - !ruby/object:Gem::Dependency
112
- name: reek
112
+ name: rubocop
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
115
  - - ">="
@@ -123,7 +123,7 @@ dependencies:
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
125
  - !ruby/object:Gem::Dependency
126
- name: rspec
126
+ name: rubocop-performance
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
129
  - - ">="
@@ -137,7 +137,7 @@ dependencies:
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
139
  - !ruby/object:Gem::Dependency
140
- name: rubocop
140
+ name: rubocop-rspec
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
143
  - - ">="
@@ -150,7 +150,7 @@ dependencies:
150
150
  - - ">="
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0'
153
- description: A middleware for Grape to add endpoint-specific throttling.
153
+ description:
154
154
  email:
155
155
  - j.gomez@drexed.com
156
156
  executables: []
@@ -158,20 +158,18 @@ extensions: []
158
158
  extra_rdoc_files: []
159
159
  files:
160
160
  - ".fasterer.yml"
161
- - ".gitattributes"
162
161
  - ".gitignore"
163
- - ".irbrc"
164
- - ".reek.yml"
165
162
  - ".rspec"
166
163
  - ".rubocop.yml"
167
- - ".ruby-version"
168
164
  - ".travis.yml"
165
+ - CHANGELOG.md
169
166
  - CODE_OF_CONDUCT.md
170
167
  - Gemfile
168
+ - Gemfile.lock
171
169
  - README.md
172
170
  - Rakefile
171
+ - _config.yml
173
172
  - bin/console
174
- - bin/rake
175
173
  - bin/setup
176
174
  - grape-throttler.gemspec
177
175
  - lib/grape-throttler.rb
@@ -197,9 +195,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
197
195
  - !ruby/object:Gem::Version
198
196
  version: '0'
199
197
  requirements: []
200
- rubyforge_project:
201
- rubygems_version: 2.7.7
198
+ rubygems_version: 3.0.6
202
199
  signing_key:
203
200
  specification_version: 4
204
- summary: Gem for throttling grape requests.
201
+ summary: Middleware for Grape to add endpoint-specific throttling.
205
202
  test_files: []
@@ -1,2 +0,0 @@
1
- # Auto detect text files and perform LF normalization
2
- * text=auto
data/.irbrc DELETED
@@ -1,44 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Awesome print
4
- begin
5
- require 'awesome_print'
6
-
7
- AwesomePrint.irb!
8
- rescue LoadError => err
9
- warn "Couldn't load awesome_print: #{err}"
10
- end
11
-
12
- # IRB
13
- require 'irb/completion'
14
-
15
- ARGV.concat %w[--readline --prompt-mode simple]
16
-
17
- IRB.conf[:PROMPT_MODE] = :SIMPLE
18
- IRB.conf[:EVAL_HISTORY] = 1000
19
- IRB.conf[:SAVE_HISTORY] = 1000
20
- IRB.conf[:HISTORY_FILE] = File.expand_path('.irbrc_history')
21
-
22
- # Rails
23
- railsrc_path = File.expand_path('.irbrc_rails')
24
-
25
- if (ENV['RAILS_ENV'] || defined?(Rails)) && File.exist?(railsrc_path)
26
- begin
27
- load railsrc_path
28
- rescue Exception => err
29
- warn "Could not load: #{railsrc_path} because of #{err}"
30
- end
31
- end
32
-
33
- # Object
34
- class Object
35
-
36
- def interesting_methods
37
- case self.class
38
- when Class then public_methods.sort - Object.public_methods
39
- when Module then public_methods.sort - Module.public_methods
40
- else public_methods.sort - Object.new.public_methods
41
- end
42
- end
43
-
44
- end
data/.reek.yml DELETED
@@ -1,22 +0,0 @@
1
- ---
2
- detectors:
3
- Attribute:
4
- enabled: false
5
- IrresponsibleModule:
6
- enabled: false
7
- MissingSafeMethod:
8
- enabled: false
9
- NilCheck:
10
- enabled: false
11
- TooManyInstanceVariables:
12
- enabled: false
13
- TooManyStatements:
14
- max_statements: 10
15
- exclude:
16
- - 'GrapeThrottler::Middleware::ThrottleMiddleware#before'
17
- UncommunicativeVariableName:
18
- accept:
19
- - '/^.$/'
20
- - '/[0-9]$/'
21
- UtilityFunction:
22
- enabled: false
@@ -1 +0,0 @@
1
- 2.5.1
data/bin/rake DELETED
@@ -1,15 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- # This file was generated by Bundler.
5
- #
6
- # The application 'rake' is installed as part of a gem, and
7
- # this file is here to facilitate running it.
8
-
9
- require 'pathname'
10
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', Pathname.new(__FILE__).realpath)
11
-
12
- require 'rubygems'
13
- require 'bundler/setup'
14
-
15
- load Gem.bin_path('rake', 'rake')