Class: Belt::TableInference
- Inherits:
-
Object
- Object
- Belt::TableInference
- Defined in:
- lib/belt/table_inference.rb
Overview
Infers DynamoDB table names from route paths by matching against tables defined in a Terraform file containing aws_dynamodb_table resources.
Instance Attribute Summary collapse
-
#available_tables ⇒ Object
readonly
Returns the value of attribute available_tables.
Instance Method Summary collapse
- #infer_tables_from_route(route) ⇒ Object
-
#initialize(dynamodb_tables_file) ⇒ TableInference
constructor
A new instance of TableInference.
Constructor Details
#initialize(dynamodb_tables_file) ⇒ TableInference
Returns a new instance of TableInference.
9 10 11 12 13 14 15 |
# File 'lib/belt/table_inference.rb', line 9 def initialize(dynamodb_tables_file) @available_tables = if dynamodb_tables_file && File.exist?(dynamodb_tables_file) parse_available_tables(dynamodb_tables_file) else [] end end |
Instance Attribute Details
#available_tables ⇒ Object (readonly)
Returns the value of attribute available_tables.
7 8 9 |
# File 'lib/belt/table_inference.rb', line 7 def available_tables @available_tables end |
Instance Method Details
#infer_tables_from_route(route) ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/belt/table_inference.rb', line 17 def infer_tables_from_route(route) path_segments = route.path.split('/').reject(&:empty?) return [] if path_segments.empty? resource_segment = path_segments.find { |seg| !seg.start_with?('{') } return [] unless resource_segment inferred = find_matching_table(resource_segment) inferred ? [inferred] : [] end |