-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor dsu export subcommand to new presenter pattern
- Loading branch information
Showing
9 changed files
with
85 additions
and
267 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,88 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative '../models/color_theme' | ||
require_relative '../models/configuration' | ||
require_relative '../support/ask' | ||
require_relative '../support/color_themable' | ||
|
||
module Dsu | ||
module Views | ||
class Export | ||
include Support::Ask | ||
include Support::ColorThemable | ||
|
||
def initialize(presenter:) | ||
def initialize(presenter:, options:) | ||
@presenter = presenter | ||
@options = options&.dup || {} | ||
@color_theme = Models::ColorTheme.find(theme_name: theme_name) | ||
end | ||
|
||
def render | ||
return presenter.display_nothing_to_export_message if presenter.nothing_to_export? | ||
|
||
response = presenter.display_export_prompt | ||
presenter.render response: response | ||
response = display_export_prompt | ||
if presenter.respond response: response | ||
display_exported_message | ||
display_exported_to_message(file_path: presenter.export_file_path) | ||
else | ||
display_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 | ||
|
||
private | ||
|
||
attr_reader :presenter | ||
attr_reader :presenter, :color_theme, :options | ||
|
||
def project_name | ||
presenter.project_name | ||
end | ||
|
||
def display_export_prompt | ||
response = ask_while(prompt_with_options(prompt: export_prompt, | ||
options: export_prompt_options), options: options) do |input| | ||
message = I18n.t('information.input.try_again', options: export_prompt_options.join(',')) | ||
puts apply_theme(message, theme_color: color_theme.info) unless export_prompt_options.include?(input) | ||
export_prompt_options.include?(input) | ||
end | ||
response == export_prompt_options.first | ||
end | ||
|
||
def display_cancelled_message | ||
puts apply_theme(I18n.t('subcommands.export.messages.cancelled'), theme_color: color_theme.info) | ||
end | ||
|
||
def display_project_does_not_exist | ||
message = I18n.t('subcommands.project.messages.does_not_exist', | ||
project_name: presenter.project_name) | ||
puts apply_theme(message, theme_color: color_theme.error) | ||
end | ||
|
||
def display_exported_message | ||
puts apply_theme(I18n.t('subcommands.export.messages.exported'), theme_color: color_theme.success) | ||
end | ||
|
||
def display_exported_to_message(file_path:) | ||
puts apply_theme(I18n.t('subcommands.export.messages.exported_to', file_path: file_path), | ||
theme_color: color_theme.success) | ||
end | ||
|
||
def display_nothing_to_export_message | ||
puts apply_theme(I18n.t('subcommands.export.messages.nothing_to_export'), theme_color: color_theme.info) | ||
end | ||
|
||
def export_prompt | ||
I18n.t('subcommands.export.prompts.export_all_confirm', count: presenter.entry_group_count) | ||
end | ||
|
||
def export_prompt_options | ||
I18n.t('subcommands.export.prompts.options') | ||
end | ||
|
||
def theme_name | ||
@theme_name ||= options.fetch(:theme_name, Models::Configuration.new.theme_name) | ||
end | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.