-
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.
dsu project rename subcommand views and tests
- Loading branch information
Showing
16 changed files
with
487 additions
and
87 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 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 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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# frozen_string_literal: true | ||
|
||
module Dsu | ||
module Support | ||
module ShortString | ||
SHORT_STRING_MAX_COUNT = 25 | ||
|
||
module_function | ||
|
||
def short_string(string:, count: SHORT_STRING_MAX_COUNT, elipsis: '...') | ||
return '' if string.blank? | ||
return string if string.length <= count | ||
|
||
# Trim to max count and cut at the last space within the limit | ||
trimmed_string = string[0...count].rpartition(' ')[0] | ||
|
||
# If no space found, trim by characters | ||
trimmed_string = string[0...(count - elipsis.length)] if trimmed_string.empty? && !string.empty? | ||
|
||
"#{trimmed_string}#{elipsis}" | ||
end | ||
end | ||
end | ||
end |
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 |
---|---|---|
@@ -0,0 +1,98 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative '../../env' | ||
require_relative '../../models/color_theme' | ||
require_relative '../../support/ask' | ||
require_relative '../../support/color_themable' | ||
|
||
module Dsu | ||
module Views | ||
module Project | ||
class Rename | ||
include Support::Ask | ||
include Support::ColorThemable | ||
|
||
attr_reader :presenter | ||
|
||
def initialize(presenter:, options: {}) | ||
@presenter = presenter | ||
@options = options&.dup || {} | ||
@color_theme = Models::ColorTheme.find(theme_name: theme_name) | ||
end | ||
|
||
def render | ||
return display_project_does_not_exist if presenter.project_does_not_exist? | ||
return display_new_project_already_exists if presenter.new_project_already_exists? | ||
return display_new_project_errors if presenter.new_project_errors.any? | ||
|
||
response = display_project_rename_prompt | ||
if presenter.respond response: response | ||
display_renamed_project_message | ||
else | ||
display_rename_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 | ||
|
||
private | ||
|
||
attr_reader :color_theme, :options | ||
|
||
def display_project_rename_prompt | ||
response = ask_while(prompt_with_options(prompt: rename_prompt, | ||
options: rename_prompt_options), options: options) do |input| | ||
message = I18n.t('information.input.try_again', options: rename_prompt_options.join(',')) | ||
puts apply_theme(message, theme_color: color_theme.info) unless rename_prompt_options.include?(input) | ||
rename_prompt_options.include?(input) | ||
end | ||
response == rename_prompt_options.first | ||
end | ||
|
||
def display_rename_project_cancelled_message | ||
message = I18n.t('subcommands.project.messages.cancelled') | ||
puts apply_theme(message, theme_color: color_theme.info) | ||
end | ||
|
||
def display_new_project_errors | ||
errors = presenter.new_project_errors.join("\n") | ||
puts apply_theme(errors, theme_color: color_theme.error) | ||
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_new_project_already_exists | ||
message = I18n.t('subcommands.project.rename.messages.new_project_already_exists', | ||
new_project_name: presenter.new_project_name) | ||
puts apply_theme(message, theme_color: color_theme.error) | ||
end | ||
|
||
def display_renamed_project_message | ||
message = I18n.t('subcommands.project.rename.messages.renamed_project', | ||
project_name: presenter.project_name, new_project_name: presenter.new_project_name) | ||
puts apply_theme(message, theme_color: color_theme.success) | ||
end | ||
|
||
def rename_prompt | ||
I18n.t('subcommands.project.rename.prompts.rename_confirm', | ||
project_name: presenter.project_name, | ||
new_project_name: presenter.new_project_name, | ||
new_project_description: presenter.new_project_description) | ||
end | ||
|
||
def rename_prompt_options | ||
I18n.t('subcommands.project.rename.prompts.rename_options') | ||
end | ||
|
||
def theme_name | ||
@theme_name ||= options.fetch(:theme_name, Models::Configuration.new.theme_name) | ||
end | ||
end | ||
end | ||
end | ||
end |
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative '../../env' | ||
require_relative '../../models/color_theme' | ||
require_relative '../../support/ask' | ||
require_relative '../../support/color_themable' | ||
require_relative 'rename' | ||
|
||
module Dsu | ||
module Views | ||
module Project | ||
class RenameByNumber < Rename | ||
def display_project_does_not_exist | ||
message = I18n.t('subcommands.project.messages.number_does_not_exist', | ||
project_number: presenter.project_number) | ||
puts apply_theme(message, theme_color: color_theme.error) | ||
end | ||
end | ||
end | ||
end | ||
end |
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
Oops, something went wrong.