Class: Strata::CLI::Generators::Table

Inherits:
Group
  • Object
show all
Defined in:
lib/strata/cli/generators/table.rb

Overview

Generates a semantic table model YAML file from field definitions.

Instance Method Summary collapse

Methods inherited from Group

exit_on_failure?, source_root

Instance Method Details

#create_model_fileObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/strata/cli/generators/table.rb', line 20

def create_model_file
  # Build output path: models/<path>/tbl.<table_name>.yml
  # e.g., "sales/customer" -> "models/sales/tbl.customer.yml"
  # Filenames are standardized to lowercase
  path_parts = path.split("/")
  table_name = path_parts.last.downcase

  if path_parts.length > 1
    # Has subdirectory: models/sales/tbl.customer.yml
    subdir = path_parts[0..-2].join("/")
    output_path = "models/#{subdir}/tbl.#{table_name}.yml"
  else
    # No subdirectory: models/tbl.customer.yml
    output_path = "models/tbl.#{table_name}.yml"
  end

  # Ensure directory exists
  empty_directory File.dirname(output_path)

  # Load template and update with user inputs
  template_content = load_template
  updated_content = update_template(template_content)

  # Write the updated template
  create_file output_path, updated_content

  say_status :created, output_path, :green
end