Class: Grape::Attack::Request
- Inherits:
-
Object
- Object
- Grape::Attack::Request
- Defined in:
- lib/grape/attack/request.rb
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
-
#throttle_options ⇒ Object
readonly
Returns the value of attribute throttle_options.
Instance Method Summary collapse
- #client_identifier ⇒ Object
-
#initialize(env) ⇒ Request
constructor
A new instance of Request.
- #method ⇒ Object
- #path ⇒ Object
- #throttle? ⇒ Boolean
Constructor Details
#initialize(env) ⇒ Request
Returns a new instance of Request.
9 10 11 12 13 14 |
# File 'lib/grape/attack/request.rb', line 9 def initialize(env) @env = env @context = env['api.endpoint'] @request = @context.routes.first @throttle_options = ::Grape::Attack::Options.new(@context.route_setting(:throttle)) end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
7 8 9 |
# File 'lib/grape/attack/request.rb', line 7 def context @context end |
#env ⇒ Object (readonly)
Returns the value of attribute env.
7 8 9 |
# File 'lib/grape/attack/request.rb', line 7 def env @env end |
#request ⇒ Object (readonly)
Returns the value of attribute request.
7 8 9 |
# File 'lib/grape/attack/request.rb', line 7 def request @request end |
#throttle_options ⇒ Object (readonly)
Returns the value of attribute throttle_options.
7 8 9 |
# File 'lib/grape/attack/request.rb', line 7 def @throttle_options end |
Instance Method Details
#client_identifier ⇒ Object
24 25 26 |
# File 'lib/grape/attack/request.rb', line 24 def client_identifier context.instance_eval(&.identifier) || env['REMOTE_ADDR'] end |
#method ⇒ Object
16 17 18 |
# File 'lib/grape/attack/request.rb', line 16 def method request.route_method end |
#path ⇒ Object
20 21 22 |
# File 'lib/grape/attack/request.rb', line 20 def path request.route_path end |
#throttle? ⇒ Boolean
28 29 30 31 32 33 |
# File 'lib/grape/attack/request.rb', line 28 def throttle? return false unless context.route_setting(:throttle).present? return true if .valid? fail ArgumentError.new(.errors.) end |