Class: Belt::Route

Inherits:
Object
  • Object
show all
Defined in:
lib/belt/route_dsl.rb

Overview

DSL for defining API Gateway routes. Ported from terraform-provider-conveyor-belt/scripts/lib/route_dsl.rb so that ‘belt routes` can parse routes.tf.rb without external dependencies.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(method, path, options = {}) ⇒ Route

Returns a new instance of Route.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/belt/route_dsl.rb', line 12

def initialize(method, path, options = {})
  @method = method.to_s.upcase
  @path = normalize_path(path)
  @auth = options[:auth]
  @lambda = options[:lambda]
  @cors = options.fetch(:cors, true)
  @tables = options[:tables] || []
  @route_type = options[:route_type] || :action
  @controller = options[:controller]
  @action = options[:action]
  @request_model = options[:request_model]&.to_s
  @response_model = options[:response_model]&.to_s
  @response_context = options[:response_context]&.to_s
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



9
10
11
# File 'lib/belt/route_dsl.rb', line 9

def action
  @action
end

#authObject (readonly)

Returns the value of attribute auth.



9
10
11
# File 'lib/belt/route_dsl.rb', line 9

def auth
  @auth
end

#controllerObject (readonly)

Returns the value of attribute controller.



9
10
11
# File 'lib/belt/route_dsl.rb', line 9

def controller
  @controller
end

#corsObject (readonly)

Returns the value of attribute cors.



9
10
11
# File 'lib/belt/route_dsl.rb', line 9

def cors
  @cors
end

#lambdaObject (readonly)

Returns the value of attribute lambda.



9
10
11
# File 'lib/belt/route_dsl.rb', line 9

def lambda
  @lambda
end

#methodObject (readonly)

Returns the value of attribute method.



9
10
11
# File 'lib/belt/route_dsl.rb', line 9

def method
  @method
end

#pathObject (readonly)

Returns the value of attribute path.



9
10
11
# File 'lib/belt/route_dsl.rb', line 9

def path
  @path
end

#request_modelObject (readonly)

Returns the value of attribute request_model.



9
10
11
# File 'lib/belt/route_dsl.rb', line 9

def request_model
  @request_model
end

#response_contextObject (readonly)

Returns the value of attribute response_context.



9
10
11
# File 'lib/belt/route_dsl.rb', line 9

def response_context
  @response_context
end

#response_modelObject (readonly)

Returns the value of attribute response_model.



9
10
11
# File 'lib/belt/route_dsl.rb', line 9

def response_model
  @response_model
end

#route_typeObject (readonly)

Returns the value of attribute route_type.



9
10
11
# File 'lib/belt/route_dsl.rb', line 9

def route_type
  @route_type
end

#tablesObject (readonly)

Returns the value of attribute tables.



9
10
11
# File 'lib/belt/route_dsl.rb', line 9

def tables
  @tables
end

Instance Method Details

#action?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/belt/route_dsl.rb', line 39

def action?
  @route_type == :action
end

#plural_resource?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/belt/route_dsl.rb', line 35

def plural_resource?
  @route_type == :resources
end

#resource?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/belt/route_dsl.rb', line 27

def resource?
  @route_type == :resource || @route_type == :resources
end

#singular_resource?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/belt/route_dsl.rb', line 31

def singular_resource?
  @route_type == :resource
end