Skip to content

Commit

Permalink
fix: Clean up some requires
Browse files Browse the repository at this point in the history
  • Loading branch information
dazuma committed Oct 13, 2023
1 parent c59f97f commit 38cf201
Show file tree
Hide file tree
Showing 11 changed files with 20 additions and 22 deletions.
3 changes: 1 addition & 2 deletions toys-core/lib/toys/cli.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# frozen_string_literal: true

require "rbconfig"
require "logger"
require "toys/completion"

module Toys
##
Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions toys-core/lib/toys/module_lookup.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# frozen_string_literal: true

require "monitor"

module Toys
##
# A helper module that provides methods to do module lookups. This is
Expand Down Expand Up @@ -56,6 +54,7 @@ def path_to_module(path)
# Create an empty ModuleLookup
#
def initialize
require "monitor"
@mutex = ::Monitor.new
@paths = []
@paths_locked = false
Expand Down
18 changes: 8 additions & 10 deletions toys-core/lib/toys/settings.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# frozen_string_literal: true

require "date"

module Toys
##
# A settings class defines the structure of application settings, i.e. the
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions toys-core/lib/toys/standard_mixins/exec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require "shellwords"

module Toys
module StandardMixins
##
Expand Down
2 changes: 0 additions & 2 deletions toys-core/lib/toys/standard_mixins/xdg.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# frozen_string_literal: true

require "fileutils"

module Toys
module StandardMixins
##
Expand Down
4 changes: 1 addition & 3 deletions toys-core/lib/toys/tool_definition.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# frozen_string_literal: true

require "set"

module Toys
##
# A ToolDefinition describes a single command that can be invoked using Toys.
Expand Down Expand Up @@ -284,7 +282,7 @@ def reset_definition
##
# Settings for this tool
#
# @return [Toys::Tool::Settings]
# @return [Toys::ToolDefinition::Settings]
#
attr_reader :settings

Expand Down
2 changes: 1 addition & 1 deletion toys-core/lib/toys/utils/exec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require "rbconfig"
require "logger"
require "shellwords"
require "stringio"

module Toys
module Utils
Expand Down
2 changes: 2 additions & 0 deletions toys-core/lib/toys/utils/help_text.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion toys-core/lib/toys/utils/standard_ui.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# frozen_string_literal: true

require "logger"
require "toys/utils/terminal"

module Toys
module Utils
##
Expand Down Expand Up @@ -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],
Expand Down
1 change: 0 additions & 1 deletion toys-core/lib/toys/utils/terminal.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# frozen_string_literal: true

require "stringio"
require "monitor"

begin
Expand Down
1 change: 1 addition & 0 deletions toys-core/lib/toys/utils/xdg.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# frozen_string_literal: true

require "fileutils"
require "toys/compat"

module Toys
Expand Down

0 comments on commit 38cf201

Please sign in to comment.