Module: Strata::CLI::Helpers::CommandContext
Constant Summary
DatasourceHelper::ADAPTER_DRIVER_GEMS
Instance Method Summary
collapse
#apply_readonly_mode, #create_adapter, #ds_config, #ensure_adapter_driver_gems!, #load_adapter_driver_gems!, #resolve_datasource, #resolve_datasource_value
Instance Method Details
#adapter ⇒ Object
15
16
17
|
# File 'lib/strata/cli/helpers/command_context.rb', line 15
def adapter
@adapter ||= create_adapter(datasource_key)
end
|
#all_tables ⇒ Object
54
55
56
|
# File 'lib/strata/cli/helpers/command_context.rb', line 54
def all_tables
table_fetch_result[:tables]
end
|
#datasource_key ⇒ Object
23
24
25
|
# File 'lib/strata/cli/helpers/command_context.rb', line 23
def datasource_key
@datasource_key ||= resolve_datasource(prompt: prompt)
end
|
#prompt ⇒ Object
19
20
21
|
# File 'lib/strata/cli/helpers/command_context.rb', line 19
def prompt
@prompt ||= TTY::Prompt.new
end
|
#table_fetch_result ⇒ Object
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/strata/cli/helpers/command_context.rb', line 27
def table_fetch_result
@table_fetch_result ||= begin
tables = with_spinner("Fetching tables from #{datasource_key}...") { adapter.tables }
if tables.empty?
say Prompts::MSG_NO_TABLES_FOUND % datasource_key, ColorHelper.warning
{tables: [], failed: false}
else
{tables: tables, failed: false}
end
rescue => e
ErrorReporter.log_error(e, context: "create table: failed fetching tables for '#{datasource_key}'")
if ErrorReporter.connection_error?(e)
say "Could not connect to datasource '#{datasource_key}'.", ColorHelper.warning
else
say "Could not fetch tables from datasource '#{datasource_key}'.", ColorHelper.warning
say "Reason: #{ErrorReporter.user_message_for(e)}", ColorHelper.warning
end
say "Hint: verify credentials/settings and run 'strata datasource test #{datasource_key}'.",
ColorHelper.info
say "Details logged to '#{ErrorReporter.log_relative_path}'.", ColorHelper.info
{tables: [], failed: true}
end
end
|