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.



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

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.



11
12
13
# File 'lib/belt/route_dsl.rb', line 11

def action
  @action
end

#authObject (readonly)

Returns the value of attribute auth.



11
12
13
# File 'lib/belt/route_dsl.rb', line 11

def auth
  @auth
end

#controllerObject (readonly)

Returns the value of attribute controller.



11
12
13
# File 'lib/belt/route_dsl.rb', line 11

def controller
  @controller
end

#corsObject (readonly)

Returns the value of attribute cors.



11
12
13
# File 'lib/belt/route_dsl.rb', line 11

def cors
  @cors
end

#lambdaObject (readonly)

Returns the value of attribute lambda.



11
12
13
# File 'lib/belt/route_dsl.rb', line 11

def lambda
  @lambda
end

#methodObject (readonly)

Returns the value of attribute method.



11
12
13
# File 'lib/belt/route_dsl.rb', line 11

def method
  @method
end

#pathObject (readonly)

Returns the value of attribute path.



11
12
13
# File 'lib/belt/route_dsl.rb', line 11

def path
  @path
end

#request_modelObject (readonly)

Returns the value of attribute request_model.



11
12
13
# File 'lib/belt/route_dsl.rb', line 11

def request_model
  @request_model
end

#response_contextObject (readonly)

Returns the value of attribute response_context.



11
12
13
# File 'lib/belt/route_dsl.rb', line 11

def response_context
  @response_context
end

#response_modelObject (readonly)

Returns the value of attribute response_model.



11
12
13
# File 'lib/belt/route_dsl.rb', line 11

def response_model
  @response_model
end

#route_typeObject (readonly)

Returns the value of attribute route_type.



11
12
13
# File 'lib/belt/route_dsl.rb', line 11

def route_type
  @route_type
end

#tablesObject (readonly)

Returns the value of attribute tables.



11
12
13
# File 'lib/belt/route_dsl.rb', line 11

def tables
  @tables
end

Instance Method Details

#action?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/belt/route_dsl.rb', line 41

def action?
  @route_type == :action
end

#plural_resource?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/belt/route_dsl.rb', line 37

def plural_resource?
  @route_type == :resources
end

#resource?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/belt/route_dsl.rb', line 29

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

#singular_resource?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/belt/route_dsl.rb', line 33

def singular_resource?
  @route_type == :resource
end