Class: Strata::CLI::SubCommands::Create

Inherits:
Thor
  • Object
show all
Extended by:
Helpers::DescriptionHelper
Includes:
AgentMode, Guard, Helpers::CommandContext, Prompts, Terminal, Thor::Actions
Defined in:
lib/strata/cli/sub_commands/create.rb

Constant Summary

Constants included from DatasourceHelper

DatasourceHelper::ADAPTER_DRIVER_GEMS

Constants included from Output

Output::THEME

Constants included from Prompts

Prompts::MIGRATION_HOOK_OPTIONS, Prompts::MSG_CONTINUE_NO_FIELDS, Prompts::MSG_CREATED_MODEL, Prompts::MSG_EDIT_MODEL_HINT, Prompts::MSG_FIELDS_CONFIRMED, Prompts::MSG_JOIN_CONDITION, Prompts::MSG_MODELS_COUNT, Prompts::MSG_MODELS_LIST_HEADER, Prompts::MSG_MODEL_DESCRIPTION, Prompts::MSG_MODEL_DISPLAY_NAME, Prompts::MSG_NO_FIELDS_CONFIRMED, Prompts::MSG_NO_MODELS_DIR, Prompts::MSG_NO_MODELS_FOUND, Prompts::MSG_NO_TABLES_FOUND, Prompts::MSG_POLICY_BYPASS_ADMIN, Prompts::MSG_POLICY_BYPASS_PROJECT, Prompts::MSG_POLICY_CONTEXT_DIM, Prompts::MSG_POLICY_CREATED, Prompts::MSG_POLICY_FIELD_NAMES, Prompts::MSG_POLICY_FIELD_TAGS, Prompts::MSG_POLICY_HINT, Prompts::MSG_POLICY_MASK_VALUE, Prompts::MSG_POLICY_MODE, Prompts::MSG_POLICY_NAME, Prompts::MSG_POLICY_PERM_SOURCE, Prompts::MSG_POLICY_TAG_KEY, Prompts::MSG_POLICY_VALUE_FROM, Prompts::MSG_RELATION_PATH, Prompts::MSG_SEARCH_TABLE, Prompts::MSG_SELECT_FROM_LIST, Prompts::MSG_SELECT_LEFT_TABLE, Prompts::MSG_SELECT_RIGHT_TABLE_ALL, Prompts::MSG_SELECT_RIGHT_TABLE_SUGGESTED, Prompts::MSG_SHOW_OTHER_TABLES

Constants included from Guard

Guard::ALLOWED_COMMANDS

Instance Method Summary collapse

Methods included from Helpers::DescriptionHelper

long_desc_from_file

Methods included from AgentMode

#agent_mode?, included, #reject_agent_mode!

Methods included from Helpers::CommandContext

#adapter, #all_tables, #datasource_key, #prompt, #table_fetch_result

Methods included from DatasourceHelper

#apply_readonly_mode, #create_adapter, #ds_config, #ensure_adapter_driver_gems!, #load_adapter_driver_gems!, #resolve_datasource, #resolve_datasource_value

Methods included from Output

format, pastel, print_error, #print_error, print_hint, #print_hint, print_info, #print_info, print_status, #print_status, print_success, #print_success, print_warning, #print_warning, shell_for, thor_color

Methods included from Prompts

default_migration_hook

Methods included from Terminal

#create_spinner, #print_table, #with_spinner

Methods included from Guard

#invoke_command

Instance Method Details

#migration(subcommand) ⇒ Object



95
96
97
98
99
100
101
102
103
104
# File 'lib/strata/cli/sub_commands/create.rb', line 95

def migration(subcommand)
  case subcommand
  when "rename"
    migration_rename
  when "swap"
    migration_swap
  else
    raise Strata::CommandError, "Unknown migration subcommand: #{subcommand}. Use 'rename' or 'swap'."
  end
end

#migration_renameObject



114
115
116
117
118
119
120
# File 'lib/strata/cli/sub_commands/create.rb', line 114

def migration_rename
  validate_entity_type(options[:entity], "rename")
  validate_required_params(options[:entity], options[:from], options[:to])

  hook = prompt_migration_hook("rename")
  create_rename_migration(options[:entity], options[:from], options[:to], hook)
end

#migration_swapObject



130
131
132
133
134
135
136
# File 'lib/strata/cli/sub_commands/create.rb', line 130

def migration_swap
  validate_entity_type(options[:entity], "swap")
  validate_required_params(options[:entity], options[:from], options[:to])

  hook = prompt_migration_hook("swap")
  create_swap_migration(options[:entity], options[:from], options[:to], hook)
end

#policy(name = nil) ⇒ Object



61
62
63
64
65
66
67
# File 'lib/strata/cli/sub_commands/create.rb', line 61

def policy(name = nil)
  attrs = policy_interactive_mode? ? collect_policy_interactive(name) : collect_policy_fast(name)
  require_relative "../generators/policy"
  Generators::Policy.new([attrs]).invoke_all
  say MSG_POLICY_CREATED % attrs[:name], :green
  say MSG_POLICY_HINT, :yellow
end

#relation(relation_path) ⇒ Object



75
76
77
78
79
80
81
82
83
84
# File 'lib/strata/cli/sub_commands/create.rb', line 75

def relation(relation_path)
  reject_agent_mode!(
    "Agent mode: write models/rel.*.yml directly.",
    code: "use_yaml_files"
  )

  return unless datasource_key

  create_relation_file(relation_path)
end

#table(table_path = nil) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/strata/cli/sub_commands/create.rb', line 38

def table(table_path = nil)
  reject_agent_mode!(
    "Agent mode: write models/tbl.*.yml directly. Use: strata datasource meta DS_KEY TABLE_NAME --agent",
    code: "use_yaml_files"
  )

  return unless datasource_key

  # If table_path provided, skip search for speed
  if table_path
    handle_table_creation_with_path(table_path)
  else
    handle_table_creation_interactive
  end
end