Class: Grape::Endpoint::Options

Inherits:
Data
  • Object
show all
Defined in:
lib/grape/endpoint/options.rb

Overview

Immutable value object holding the keyword inputs passed to Grape::Endpoint.new. Internal to Grape::Endpoint, which builds it from the **options Hash in #initialize so the public options reader stays a plain Hash for downstream gems (e.g. grape-swagger).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path:, http_methods:, api:, route_options: {}, app: nil, params: {}, requirements: nil, anchor: true) ⇒ Options

Returns a new instance of Options.



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/grape/endpoint/options.rb', line 10

def initialize(path:, http_methods:, api:, route_options: {}, app: nil, params: {}, requirements: nil, anchor: true)
  # +Array()+ hands back the very Array it was given, so defaulting an
  # empty one by appending would append to the caller's Array — and raise
  # FrozenError on a frozen one. Build a new Array instead of growing
  # theirs: nothing about constructing an endpoint should be visible in
  # the path the caller passed in.
  paths = Array(path)
  super(
    path: paths.presence || ['/'],
    http_methods: Array(http_methods),
    api:, route_options:, app:, params:, requirements:, anchor:
  )
end

Instance Attribute Details

#anchorObject (readonly)

Returns the value of attribute anchor

Returns:

  • the current value of anchor



9
10
11
# File 'lib/grape/endpoint/options.rb', line 9

def anchor
  @anchor
end

#apiObject (readonly)

Returns the value of attribute api

Returns:

  • the current value of api



9
10
11
# File 'lib/grape/endpoint/options.rb', line 9

def api
  @api
end

#appObject (readonly)

Returns the value of attribute app

Returns:

  • the current value of app



9
10
11
# File 'lib/grape/endpoint/options.rb', line 9

def app
  @app
end

#http_methodsObject (readonly)

Returns the value of attribute http_methods

Returns:

  • the current value of http_methods



9
10
11
# File 'lib/grape/endpoint/options.rb', line 9

def http_methods
  @http_methods
end

#paramsObject (readonly)

Returns the value of attribute params

Returns:

  • the current value of params



9
10
11
# File 'lib/grape/endpoint/options.rb', line 9

def params
  @params
end

#pathObject (readonly)

Returns the value of attribute path

Returns:

  • the current value of path



9
10
11
# File 'lib/grape/endpoint/options.rb', line 9

def path
  @path
end

#requirementsObject (readonly)

Returns the value of attribute requirements

Returns:

  • the current value of requirements



9
10
11
# File 'lib/grape/endpoint/options.rb', line 9

def requirements
  @requirements
end

#route_optionsObject (readonly)

Returns the value of attribute route_options

Returns:

  • the current value of route_options



9
10
11
# File 'lib/grape/endpoint/options.rb', line 9

def route_options
  @route_options
end