Class: Grape::Attack::Request
- Inherits:
-
Object
- Object
- Grape::Attack::Request
show all
- Defined in:
- lib/grape/attack/request.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
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
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
28
29
30
|
# File 'lib/grape/attack/request.rb', line 28
def method_missing(method_name, *args, &block)
context.public_send(method_name, *args, &block)
end
|
Instance Attribute Details
#context ⇒ Object
Returns the value of attribute context.
7
8
9
|
# File 'lib/grape/attack/request.rb', line 7
def context
@context
end
|
#env ⇒ Object
Returns the value of attribute env.
7
8
9
|
# File 'lib/grape/attack/request.rb', line 7
def env
@env
end
|
#request ⇒ Object
Returns the value of attribute request.
7
8
9
|
# File 'lib/grape/attack/request.rb', line 7
def request
@request
end
|
#throttle_options ⇒ Object
Returns the value of attribute throttle_options.
7
8
9
|
# File 'lib/grape/attack/request.rb', line 7
def throttle_options
@throttle_options
end
|
Instance Method Details
#client_identifier ⇒ Object
36
37
38
|
# File 'lib/grape/attack/request.rb', line 36
def client_identifier
self.instance_eval(&throttle_options.identifier) || env['HTTP_X_REAL_IP'] || env['REMOTE_ADDR']
end
|
#method ⇒ Object
16
17
18
|
# File 'lib/grape/attack/request.rb', line 16
def method
request.route_method
end
|
#params ⇒ Object
24
25
26
|
# File 'lib/grape/attack/request.rb', line 24
def params
request.route_params
end
|
#path ⇒ Object
20
21
22
|
# File 'lib/grape/attack/request.rb', line 20
def path
request.route_path
end
|
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
32
33
34
|
# File 'lib/grape/attack/request.rb', line 32
def respond_to_missing?(method_name, include_private = false)
context.respond_to?(method_name)
end
|
#throttle? ⇒ Boolean
40
41
42
43
44
45
|
# File 'lib/grape/attack/request.rb', line 40
def throttle?
return false unless context.route_setting(:throttle).present?
return true if throttle_options.valid?
fail ArgumentError.new(throttle_options.errors.full_messages)
end
|