Class: Belt::CLI::TablesCommand

Inherits:
Object
  • Object
show all
Includes:
AppDetection
Defined in:
lib/belt/cli/tables_command.rb

Defined Under Namespace

Classes: ModelParser, SchemaParser

Constant Summary collapse

SCHEMA_FILE =
'infrastructure/schema.tf.rb'
MODULE_DIR =
'infrastructure/modules/app'

Class Method Summary collapse

Instance Method Summary collapse

Methods included from AppDetection

#detect_app_name, #detect_environments, #detect_namespace, #s3_safe_name

Constructor Details

#initialize(env, quiet: false) ⇒ TablesCommand

Returns a new instance of TablesCommand.



42
43
44
45
46
# File 'lib/belt/cli/tables_command.rb', line 42

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

.sync_all_environmentsObject

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 File.exist?(SCHEMA_FILE)

  # With the module approach, we only need to generate once into modules/app/
  new(nil, quiet: true).run
end

Instance Method Details

#runObject



48
49
50
51
52
53
54
55
56
57
# File 'lib/belt/cli/tables_command.rb', line 48

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