Class: Dsu::Views::Project::Use

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

Direct Known Subclasses

UseByNumber

Instance Attribute Summary collapse

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: {}) ⇒ Use

Returns a new instance of Use.



17
18
19
20
21
# File 'lib/dsu/views/project/use.rb', line 17

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

Instance Attribute Details

#presenterObject (readonly)

Returns the value of attribute presenter.



15
16
17
# File 'lib/dsu/views/project/use.rb', line 15

def presenter
  @presenter
end

Instance Method Details

#renderObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/dsu/views/project/use.rb', line 23

def render
  return display_project_does_not_exist if presenter.project_does_not_exist?
  return display_project_already_current_project if presenter.already_current_project?
  return display_project_errors if presenter.project_errors.any?

  response = display_project_use_prompt
  if presenter.respond response: response
    display_using_project_message
  else
    display_use_project_cancelled_message
  end
rescue StandardError => e
  puts apply_theme(e.message, theme_color: color_theme.error)
  puts apply_theme(e.backtrace_locations.join("\n"), theme_color: color_theme.error) if Dsu.env.local?
end