summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAbinoam P. Marques Jr <abinoam@gmail.com>2017-07-01 22:57:07 -0300
committerAbinoam P. Marques Jr <abinoam@gmail.com>2017-07-01 23:42:10 -0300
commit92872eaf3e200df50fac5fe5e8ce1c8b2d1373aa (patch)
tree5f548ad08c4e96752536153c756841d97fd1e67c /lib
parent492b61377ceabe3c4d91ba8ed44ca245dbc5f43c (diff)
downloadhighline-92872eaf3e200df50fac5fe5e8ce1c8b2d1373aa.tar.gz
Apply manual fixes for rubocop warnings
Diffstat (limited to 'lib')
-rw-r--r--lib/highline/builtin_styles.rb53
-rw-r--r--lib/highline/color_scheme.rb36
-rw-r--r--lib/highline/list.rb3
-rw-r--r--lib/highline/list_renderer.rb7
-rw-r--r--lib/highline/menu.rb48
-rw-r--r--lib/highline/paginator.rb4
-rwxr-xr-xlib/highline/question.rb7
-rw-r--r--lib/highline/question_asker.rb3
8 files changed, 93 insertions, 68 deletions
diff --git a/lib/highline/builtin_styles.rb b/lib/highline/builtin_styles.rb
index 175497f..acd06b2 100644
--- a/lib/highline/builtin_styles.rb
+++ b/lib/highline/builtin_styles.rb
@@ -29,11 +29,13 @@ class HighLine
style = String(style_name).upcase
const_set style, code
- const_set style + "_STYLE", Style.new(name: style_name, code: code, builtin: true)
+ const_set style + "_STYLE",
+ Style.new(name: style_name, code: code, builtin: true)
end
# Basic Style names like CLEAR, BOLD, UNDERLINE
- STYLES = %w[CLEAR RESET BOLD DARK UNDERLINE UNDERSCORE BLINK REVERSE CONCEALED].freeze
+ STYLES = %w[CLEAR RESET BOLD DARK UNDERLINE
+ UNDERSCORE BLINK REVERSE CONCEALED].freeze
# A Hash with the basic colors an their ANSI escape codes.
COLOR_LIST = {
@@ -64,7 +66,9 @@ class HighLine
end
# The builtin styles basic colors like black, red, green.
- BASIC_COLORS = %w[BLACK RED GREEN YELLOW BLUE MAGENTA CYAN WHITE GRAY GREY NONE].freeze
+ BASIC_COLORS =
+ %w[BLACK RED GREEN YELLOW BLUE
+ MAGENTA CYAN WHITE GRAY GREY NONE].freeze
colors = BASIC_COLORS.dup
BASIC_COLORS.each do |color|
@@ -97,27 +101,28 @@ class HighLine
# builtin constants (without explicitly defining them)
# @param name [Symbol] missing constant name
def const_missing(name)
- if name.to_s =~ RGB_COLOR_PATTERN
- on = Regexp.last_match(1)
- suffix = Regexp.last_match(4)
-
- code_name = if suffix
- Regexp.last_match(1).to_s + Regexp.last_match(2) + Regexp.last_match(3)
- else
- name.to_s
- end
-
- style_name = code_name + '_STYLE'
- style = Style.rgb(Regexp.last_match(3))
- style = style.on if on
-
- const_set(style_name, style)
- const_set(code_name, style.code)
-
- suffix ? style : style.code
- else
- raise NameError, "Bad color or uninitialized constant #{name}"
- end
+ raise NameError, "Bad color or uninitialized constant #{name}" unless
+ name.to_s =~ RGB_COLOR_PATTERN
+
+ on = Regexp.last_match(1)
+ suffix = Regexp.last_match(4)
+
+ code_name = if suffix
+ Regexp.last_match(1).to_s +
+ Regexp.last_match(2) +
+ Regexp.last_match(3)
+ else
+ name.to_s
+ end
+
+ style_name = code_name + '_STYLE'
+ style = Style.rgb(Regexp.last_match(3))
+ style = style.on if on
+
+ const_set(style_name, style)
+ const_set(code_name, style.code)
+
+ suffix ? style : style.code
end
end
end
diff --git a/lib/highline/color_scheme.rb b/lib/highline/color_scheme.rb
index a776fbf..414ebb1 100644
--- a/lib/highline/color_scheme.rb
+++ b/lib/highline/color_scheme.rb
@@ -18,7 +18,8 @@ class HighLine
#
# A ColorScheme contains named sets of HighLine color constants.
#
- # @example Instantiating a color scheme, applying it to HighLine, and using it:
+ # @example Instantiating a color scheme, applying it to HighLine,
+ # and using it:
# ft = HighLine::ColorScheme.new do |cs|
# cs[:headline] = [ :bold, :yellow, :on_black ]
# cs[:horizontal_line] = [ :bold, :white ]
@@ -93,14 +94,19 @@ class HighLine
# @param color_tag [#to_sym]
# @param constants [Array<Symbol>] Array of Style symbols
def []=(color_tag, constants)
- @scheme[to_symbol(color_tag)] = HighLine::Style.new(name: color_tag.to_s.downcase.to_sym,
- list: constants, no_index: true)
+ @scheme[to_symbol(color_tag)] =
+ HighLine::Style.new(name: color_tag.to_s.downcase.to_sym,
+ list: constants,
+ no_index: true)
end
# Retrieve the color scheme hash (in original definition format)
# @return [Hash] scheme as Hash. It may be reused in a new ColorScheme.
def to_hash
- @scheme.each_with_object({}) { |pair, hsh| key, value = pair; hsh[key] = value.list; }
+ @scheme.each_with_object({}) do |pair, hsh|
+ key, value = pair
+ hsh[key] = value.list
+ end
end
private
@@ -123,23 +129,23 @@ class HighLine
# A sample ColorScheme.
class SampleColorScheme < ColorScheme
+ SAMPLE_SCHEME = {
+ critical: %i[yellow on_red],
+ error: %i[bold red],
+ warning: %i[bold yellow],
+ notice: %i[bold magenta],
+ info: %i[bold cyan],
+ debug: %i[bold green],
+ row_even: [:cyan],
+ row_odd: [:magenta]
+ }.freeze
#
# Builds the sample scheme with settings for <tt>:critical</tt>,
# <tt>:error</tt>, <tt>:warning</tt>, <tt>:notice</tt>, <tt>:info</tt>,
# <tt>:debug</tt>, <tt>:row_even</tt>, and <tt>:row_odd</tt> colors.
#
def initialize(_h = nil)
- scheme = {
- critical: %i[yellow on_red],
- error: %i[bold red],
- warning: %i[bold yellow],
- notice: %i[bold magenta],
- info: %i[bold cyan],
- debug: %i[bold green],
- row_even: [:cyan],
- row_odd: [:magenta]
- }
- super(scheme)
+ super(SAMPLE_SCHEME)
end
end
end
diff --git a/lib/highline/list.rb b/lib/highline/list.rb
index 8e0a0b0..6ca876f 100644
--- a/lib/highline/list.rb
+++ b/lib/highline/list.rb
@@ -66,7 +66,8 @@ class HighLine
build
end
- # Transpose the (already sliced by rows) list, turning its rows into columns.
+ # Transpose the (already sliced by rows) list,
+ # turning its rows into columns.
# @return [self]
def transpose
first_row = @list[0]
diff --git a/lib/highline/list_renderer.rb b/lib/highline/list_renderer.rb
index 8052d71..be1aa95 100644
--- a/lib/highline/list_renderer.rb
+++ b/lib/highline/list_renderer.rb
@@ -91,7 +91,8 @@ class HighLine::ListRenderer
items.to_ary.map do |item|
item = String(item)
template = ERB.new(item, nil, "%")
- template_renderer = HighLine::TemplateRenderer.new(template, self, highline)
+ template_renderer =
+ HighLine::TemplateRenderer.new(template, self, highline)
template_renderer.render
end
end
@@ -224,13 +225,13 @@ class HighLine::ListRenderer
row_join_string.size
end
- def get_col_count
+ def col_count_calculate
(line_size_limit + row_join_str_size) /
(items_max_length + row_join_str_size)
end
def col_count
- option || get_col_count
+ option || col_count_calculate
end
def right_padded_items
diff --git a/lib/highline/menu.rb b/lib/highline/menu.rb
index d9a2b6e..dc8ec93 100644
--- a/lib/highline/menu.rb
+++ b/lib/highline/menu.rb
@@ -13,7 +13,8 @@ require "highline/menu/item"
class HighLine
#
- # Menu objects encapsulate all the details of a call to {HighLine#choose HighLine#choose}.
+ # Menu objects encapsulate all the details of a call to
+ # {HighLine#choose HighLine#choose}.
# Using the accessors and {Menu#choice} and {Menu#choices}, the block passed
# to {HighLine#choose} can detail all aspects of menu display and control.
#
@@ -179,7 +180,8 @@ class HighLine
# cli.choose do |menu|
# menu.shell = true
#
- # menu.choice(:load, text: 'Load a file', help: "Load a file using your favourite editor.")
+ # menu.choice(:load, text: 'Load a file',
+ # help: "Load a file using your favourite editor.")
# menu.choice(:save, help: "Save data in file.")
# menu.choice(:quit, help: "Exit program.")
#
@@ -194,11 +196,11 @@ class HighLine
end
#
- # This method helps reduce the namespaces in the original call, which would look
- # like this: HighLine::Menu::Item.new(...)
+ # This method helps reduce the namespaces in the original call,
+ # which would look like this: HighLine::Menu::Item.new(...)
# With #build_item, it looks like this: menu.build_item(...)
- # @param *args splat args, the same args you would pass to an initialization of
- # HighLine::Menu::Item
+ # @param *args splat args, the same args you would pass to an
+ # initialization of HighLine::Menu::Item
# @return [HighLine::Menu::Item] the menu item
def build_item(*args)
@@ -206,8 +208,8 @@ class HighLine
end
#
- # Adds an item directly to the menu. If you want more configuraiton or options,
- # use this method
+ # Adds an item directly to the menu. If you want more configuration
+ # or options, use this method
#
# @param item [Menu::Item] item containing choice fields and more
# @return [void]
@@ -223,7 +225,8 @@ class HighLine
# warned:</b> An _action_ set here will apply to *all* provided
# _names_. This is considered to be a feature, so you can easily
# hand-off interface processing to a different chunk of code.
- # @param names [Array<#to_s>] menu item titles/headers/names to be displayed.
+ # @param names [Array<#to_s>] menu item titles/headers/names to be
+ # displayed.
# @param action (see #choice)
# @return [void]
# @example (see HighLine::Menu#initialize)
@@ -281,12 +284,17 @@ class HighLine
return if @items.include?(:help)
topics = @help.keys.sort
- help_help = @help.include?("help") ? @help["help"] :
- "This command will display helpful messages about " \
- "functionality, like this one. To see the help for " \
- "a specific topic enter:\n\thelp [TOPIC]\nTry asking " \
- "for help on any of the following:\n\n" \
- "<%= list(#{topics.inspect}, :columns_across) %>"
+ help_help =
+ if @help.include?("help")
+ @help["help"]
+ else
+ "This command will display helpful messages about " \
+ "functionality, like this one. To see the help for " \
+ "a specific topic enter:\n\thelp [TOPIC]\nTry asking " \
+ "for help on any of the following:\n\n" \
+ "<%= list(#{topics.inspect}, :columns_across) %>"
+ end
+
choice(:help, help_help) do |_command, topic|
topic.strip!
topic.downcase!
@@ -302,8 +310,8 @@ class HighLine
# Used to set help for arbitrary topics. Use the topic <tt>"help"</tt>
# to override the default message. Mainly for internal use.
#
- # @param topic [String] the menu item header/title/name to be associated with
- # a help message.
+ # @param topic [String] the menu item header/title/name to be associated
+ # with a help message.
# @param help [String] the help message to be associated with the menu
# item/title/name.
def help(topic, help)
@@ -387,8 +395,10 @@ class HighLine
# rules for this Menu object. If an action was provided for the
# selection, it will be executed as described in {#choice}.
#
- # @param highline_context [HighLine] a HighLine instance to be used as context.
- # @param selection [String, Integer] index or title of the selected menu item.
+ # @param highline_context [HighLine] a HighLine instance to be used
+ # as context.
+ # @param selection [String, Integer] index or title of the selected
+ # menu item.
# @param details additional parameter to be passed when in shell mode.
# @return [nil, Object] if @nil_on_handled is set it returns +nil+,
# else it returns the action return value.
diff --git a/lib/highline/paginator.rb b/lib/highline/paginator.rb
index 9be3821..9da8735 100644
--- a/lib/highline/paginator.rb
+++ b/lib/highline/paginator.rb
@@ -39,8 +39,8 @@ class HighLine
end
#
- # Ask user if they wish to continue paging output. Allows them to type "q" to
- # cancel the paging process.
+ # Ask user if they wish to continue paging output. Allows them to
+ # type "q" to cancel the paging process.
#
def continue_paging?
command = highline.new_scope.ask(
diff --git a/lib/highline/question.rb b/lib/highline/question.rb
index 98b3fa9..b630ef9 100755
--- a/lib/highline/question.rb
+++ b/lib/highline/question.rb
@@ -60,11 +60,11 @@ class HighLine
@case = nil
@in = nil
@first_answer = nil
- @directory = Pathname.new(File.expand_path(File.dirname($PROGRAM_NAME)))
@glob = "*"
+ @overwrite = false
@user_responses = {}
@internal_responses = default_responses_hash
- @overwrite = false
+ @directory = Pathname.new(File.expand_path(File.dirname($PROGRAM_NAME)))
# allow block to override settings
yield self if block_given?
@@ -548,7 +548,8 @@ class HighLine
# Provides the String to be asked when at an error situation.
# It may be just the question itself (repeat on error).
# @return [self] if :ask_on_error on responses Hash is set to :question
- # @return [String] if :ask_on_error on responses Hash is set to something else
+ # @return [String] if :ask_on_error on responses Hash is set to
+ # something else
def ask_on_error_msg
if final_responses[:ask_on_error] == :question
self
diff --git a/lib/highline/question_asker.rb b/lib/highline/question_asker.rb
index 845914a..0d124b1 100644
--- a/lib/highline/question_asker.rb
+++ b/lib/highline/question_asker.rb
@@ -31,7 +31,8 @@ class HighLine
question.convert
if question.confirm
- raise NoConfirmationQuestionError unless @highline.send(:confirm, question)
+ confirmation = @highline.send(:confirm, question)
+ raise NoConfirmationQuestionError unless confirmation
end
rescue ExplainableError => e
explain_error(e.explanation_key)