Class: Grape::Attack::Request

Inherits:
Object
  • Object
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

#contextObject (readonly)

Returns the value of attribute context.



7
8
9
# File 'lib/grape/attack/request.rb', line 7

def context
  @context
end

#envObject (readonly)

Returns the value of attribute env.



7
8
9
# File 'lib/grape/attack/request.rb', line 7

def env
  @env
end

#requestObject (readonly)

Returns the value of attribute request.



7
8
9
# File 'lib/grape/attack/request.rb', line 7

def request
  @request
end

#throttle_optionsObject (readonly)

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_identifierObject



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

#methodObject



16
17
18
# File 'lib/grape/attack/request.rb', line 16

def method
  request.route_method
end

#paramsObject



24
25
26
# File 'lib/grape/attack/request.rb', line 24

def params
  request.route_params
end

#pathObject



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

Returns:

  • (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

Returns:

  • (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