Class: Belt::CLI::TablesCommand
- Inherits:
-
Object
- Object
- Belt::CLI::TablesCommand
- Includes:
- AppDetection
- Defined in:
- lib/belt/cli/tables_command.rb
Defined Under Namespace
Classes: ModelParser, SchemaParser
Constant Summary collapse
- SCHEMA_FILE_CANDIDATES =
['config/schema.tf.rb', 'infrastructure/schema.tf.rb'].freeze
- MODULE_DIR =
'infrastructure/modules/app'
Class Method Summary collapse
- .run(args) ⇒ Object
- .schema_file_path ⇒ Object
-
.sync_all_environments ⇒ Object
Automatically sync dynamodb.tf in the app module.
Instance Method Summary collapse
-
#initialize(env, quiet: false) ⇒ TablesCommand
constructor
A new instance of TablesCommand.
- #run ⇒ Object
Methods included from AppDetection
#detect_app_name, #detect_environments, #detect_namespace, #find_routes_file_path, #find_schema_file_path, #s3_safe_name
Constructor Details
#initialize(env, quiet: false) ⇒ TablesCommand
Returns a new instance of TablesCommand.
46 47 48 49 50 |
# File 'lib/belt/cli/tables_command.rb', line 46 def initialize(env, quiet: false) @env = env @quiet = quiet @app_name = detect_app_name end |
Class Method Details
.run(args) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/belt/cli/tables_command.rb', line 16 def self.run(args) env = EnvResolver.resolve(args) if env.nil? puts 'Usage: belt setup tables [environment]' puts "\nReads schema.tf.rb and generates dynamodb.tf in the app module." puts 'You can also set BELT_ENV to skip the environment argument.' puts "\nExamples:" puts ' belt setup tables' puts ' belt setup tables dev' puts ' BELT_ENV=dev belt setup tables' exit 1 end new(env).run end |
.schema_file_path ⇒ Object
42 43 44 |
# File 'lib/belt/cli/tables_command.rb', line 42 def self.schema_file_path SCHEMA_FILE_CANDIDATES.find { |f| File.exist?(f) } end |
.sync_all_environments ⇒ Object
Automatically sync dynamodb.tf in the app module. Called by generators after updating schema.tf.rb.
35 36 37 38 39 40 |
# File 'lib/belt/cli/tables_command.rb', line 35 def self.sync_all_environments return unless schema_file_path # With the module approach, we only need to generate once into modules/app/ new(nil, quiet: true).run end |
Instance Method Details
#run ⇒ Object
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/belt/cli/tables_command.rb', line 52 def run validate! models = parse_schema if models.empty? puts "No models found in #{SCHEMA_FILE}" unless @quiet return end generate_dynamodb_tf(models) end |