From 38cf2013b7d66d3b43cc4135bc5992e3af0ed2c4 Mon Sep 17 00:00:00 2001 From: Daniel Azuma Date: Fri, 13 Oct 2023 11:27:26 -0700 Subject: [PATCH] fix: Clean up some requires --- toys-core/lib/toys/cli.rb | 3 +-- toys-core/lib/toys/module_lookup.rb | 3 +-- toys-core/lib/toys/settings.rb | 18 ++++++++---------- toys-core/lib/toys/standard_mixins/exec.rb | 2 ++ toys-core/lib/toys/standard_mixins/xdg.rb | 2 -- toys-core/lib/toys/tool_definition.rb | 4 +--- toys-core/lib/toys/utils/exec.rb | 2 +- toys-core/lib/toys/utils/help_text.rb | 2 ++ toys-core/lib/toys/utils/standard_ui.rb | 4 +++- toys-core/lib/toys/utils/terminal.rb | 1 - toys-core/lib/toys/utils/xdg.rb | 1 + 11 files changed, 20 insertions(+), 22 deletions(-) diff --git a/toys-core/lib/toys/cli.rb b/toys-core/lib/toys/cli.rb index 5bd29d6c..d53d772e 100644 --- a/toys-core/lib/toys/cli.rb +++ b/toys-core/lib/toys/cli.rb @@ -1,8 +1,6 @@ # frozen_string_literal: true require "rbconfig" -require "logger" -require "toys/completion" module Toys ## @@ -567,6 +565,7 @@ def default_error_handler # def default_logger_factory proc do + require "logger" logger = ::Logger.new($stderr) logger.level = ::Logger::WARN logger diff --git a/toys-core/lib/toys/module_lookup.rb b/toys-core/lib/toys/module_lookup.rb index 4b80ca43..edcede90 100644 --- a/toys-core/lib/toys/module_lookup.rb +++ b/toys-core/lib/toys/module_lookup.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -require "monitor" - module Toys ## # A helper module that provides methods to do module lookups. This is @@ -56,6 +54,7 @@ def path_to_module(path) # Create an empty ModuleLookup # def initialize + require "monitor" @mutex = ::Monitor.new @paths = [] @paths_locked = false diff --git a/toys-core/lib/toys/settings.rb b/toys-core/lib/toys/settings.rb index 3c8de72c..013cb769 100644 --- a/toys-core/lib/toys/settings.rb +++ b/toys-core/lib/toys/settings.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -require "date" - module Toys ## # A settings class defines the structure of application settings, i.e. the @@ -488,7 +486,7 @@ def for_scalar(value) def convert(val, klass) return val if val.is_a?(klass) begin - CONVERTERS[klass].call(val) + CONVERTERS[klass.name].call(val) rescue ::StandardError ILLEGAL_VALUE end @@ -564,13 +562,13 @@ def convert(val, klass) # @private # CONVERTERS = { - ::Date => date_converter, - ::DateTime => datetime_converter, - ::Float => float_converter, - ::Integer => integer_converter, - ::Regexp => regexp_converter, - ::Symbol => symbol_converter, - ::Time => time_converter, + "Date" => date_converter, + "DateTime" => datetime_converter, + "Float" => float_converter, + "Integer" => integer_converter, + "Regexp" => regexp_converter, + "Symbol" => symbol_converter, + "Time" => time_converter, }.freeze end diff --git a/toys-core/lib/toys/standard_mixins/exec.rb b/toys-core/lib/toys/standard_mixins/exec.rb index 9377e991..540a3222 100644 --- a/toys-core/lib/toys/standard_mixins/exec.rb +++ b/toys-core/lib/toys/standard_mixins/exec.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +require "shellwords" + module Toys module StandardMixins ## diff --git a/toys-core/lib/toys/standard_mixins/xdg.rb b/toys-core/lib/toys/standard_mixins/xdg.rb index 92482af5..c16864d8 100644 --- a/toys-core/lib/toys/standard_mixins/xdg.rb +++ b/toys-core/lib/toys/standard_mixins/xdg.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -require "fileutils" - module Toys module StandardMixins ## diff --git a/toys-core/lib/toys/tool_definition.rb b/toys-core/lib/toys/tool_definition.rb index 403007c0..b85cb2c3 100644 --- a/toys-core/lib/toys/tool_definition.rb +++ b/toys-core/lib/toys/tool_definition.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -require "set" - module Toys ## # A ToolDefinition describes a single command that can be invoked using Toys. @@ -284,7 +282,7 @@ def reset_definition ## # Settings for this tool # - # @return [Toys::Tool::Settings] + # @return [Toys::ToolDefinition::Settings] # attr_reader :settings diff --git a/toys-core/lib/toys/utils/exec.rb b/toys-core/lib/toys/utils/exec.rb index ce165260..aa8d1946 100644 --- a/toys-core/lib/toys/utils/exec.rb +++ b/toys-core/lib/toys/utils/exec.rb @@ -2,7 +2,7 @@ require "rbconfig" require "logger" -require "shellwords" +require "stringio" module Toys module Utils diff --git a/toys-core/lib/toys/utils/help_text.rb b/toys-core/lib/toys/utils/help_text.rb index bdd560ee..baa13aed 100644 --- a/toys-core/lib/toys/utils/help_text.rb +++ b/toys-core/lib/toys/utils/help_text.rb @@ -351,6 +351,7 @@ class HelpStringAssembler def initialize(tool, executable_name, delegates, subtools, search_term, show_source_path, separate_sources, indent, indent2, wrap_width, styled) require "toys/utils/terminal" + require "stringio" @tool = tool @executable_name = executable_name @delegates = delegates @@ -667,6 +668,7 @@ class ListStringAssembler def initialize(tool, subtools, recursive, search_term, separate_sources, indent, wrap_width, styled) require "toys/utils/terminal" + require "stringio" @tool = tool @subtools = subtools @recursive = recursive diff --git a/toys-core/lib/toys/utils/standard_ui.rb b/toys-core/lib/toys/utils/standard_ui.rb index d1b1f278..d472dbc7 100644 --- a/toys-core/lib/toys/utils/standard_ui.rb +++ b/toys-core/lib/toys/utils/standard_ui.rb @@ -1,5 +1,8 @@ # frozen_string_literal: true +require "logger" +require "toys/utils/terminal" + module Toys module Utils ## @@ -29,7 +32,6 @@ class StandardUI # def initialize(output: nil) @terminal = output || $stderr - require "toys/utils/terminal" @terminal = Terminal.new(output: @terminal) unless @terminal.is_a?(Terminal) @log_header_severity_styles = { "FATAL" => [:bright_magenta, :bold, :underline], diff --git a/toys-core/lib/toys/utils/terminal.rb b/toys-core/lib/toys/utils/terminal.rb index 3c79cfcf..4b93e71c 100644 --- a/toys-core/lib/toys/utils/terminal.rb +++ b/toys-core/lib/toys/utils/terminal.rb @@ -1,6 +1,5 @@ # frozen_string_literal: true -require "stringio" require "monitor" begin diff --git a/toys-core/lib/toys/utils/xdg.rb b/toys-core/lib/toys/utils/xdg.rb index b16d9e60..3bc4361c 100644 --- a/toys-core/lib/toys/utils/xdg.rb +++ b/toys-core/lib/toys/utils/xdg.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true +require "fileutils" require "toys/compat" module Toys