Class: Dsu::Views::Import

Inherits:
Object
  • Object
show all
Includes:
Support::Ask, Support::ColorThemable
Defined in:
lib/dsu/views/import.rb

Direct Known Subclasses

ImportDates

Instance Method Summary collapse

Methods included from Support::ColorThemable

apply_theme, #prompt_with_options

Methods included from Support::Ask

#ask_while, #yes?

Constructor Details

#initialize(presenter:, options:) ⇒ Import

Returns a new instance of Import.



13
14
15
16
17
# File 'lib/dsu/views/import.rb', line 13

def initialize(presenter:, options:)
  @presenter = presenter
  @options = options&.dup || {}
  @color_theme = Models::ColorTheme.find(theme_name: theme_name)
end

Instance Method Details

#renderObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/dsu/views/import.rb', line 19

def render
  return display_import_file_not_exist_message unless presenter.import_file_path_exist?
  return display_nothing_to_import_message if presenter.nothing_to_import?

  response = display_import_prompt
  return display_cancelled_message unless response

  response = display_project_override_prompt if presenter.overriding_project?
  return display_cancelled_message unless response

  display_import_messages presenter.respond
rescue StandardError => e
  puts apply_theme(e.backtrace_locations.join("\n"), theme_color: color_theme.error) if Dsu.env.local?
  message = I18n.t('subcommands.import.messages.import_error_raised', error: e.message)
  puts apply_theme(message, theme_color: color_theme.error)
end