Skip to content

Commit

Permalink
Address new offenses, update syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
flash-gordon committed Jan 4, 2025
1 parent b6dbccf commit 562394b
Show file tree
Hide file tree
Showing 23 changed files with 78 additions and 69 deletions.
4 changes: 4 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -269,3 +269,7 @@ Naming/VariableNumber:

Naming/BinaryOperatorParameterName:
Enabled: false

Style/OpenStructUse:
Exclude:
- "spec/**/*.rb"
10 changes: 5 additions & 5 deletions lib/dry/system/component_dir.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ def each_file

def files(namespace)
if namespace.path?
Dir[File.join(full_path, namespace.path, "**", RB_GLOB)].sort
::Dir[::File.join(full_path, namespace.path, "**", RB_GLOB)]
else
non_root_paths = config.namespaces.to_a.reject(&:root?).map(&:path)

Dir[File.join(full_path, "**", RB_GLOB)].reject { |file_path|
::Dir[::File.join(full_path, "**", RB_GLOB)].reject { |file_path|
Pathname(file_path).relative_path_from(full_path).to_s.start_with?(*non_root_paths)
}.sort
}
end
end

Expand Down Expand Up @@ -155,9 +155,9 @@ def component_options
}
end

def method_missing(name, *args, &block)
def method_missing(name, ...)
if config.respond_to?(name)
config.public_send(name, *args, &block)
config.public_send(name, ...)
else
super
end
Expand Down
6 changes: 3 additions & 3 deletions lib/dry/system/config/component_dir.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module System
module Config
# @api public
class ComponentDir
include Dry::Configurable
include ::Dry::Configurable

# @!group Settings

Expand Down Expand Up @@ -211,9 +211,9 @@ def auto_register?

private

def method_missing(name, *args, &block)
def method_missing(name, ...)
if config.respond_to?(name)
config.public_send(name, *args, &block)
config.public_send(name, ...)
else
super
end
Expand Down
10 changes: 5 additions & 5 deletions lib/dry/system/config/component_dirs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def initialize

# @api private
def initialize_copy(source)
@dirs = source.dirs.map { |path, dir| [path, dir.dup] }.to_h
@dirs = source.dirs.to_h { |path, dir| [path, dir.dup] }
@defaults = source.defaults.dup
end

Expand Down Expand Up @@ -221,8 +221,8 @@ def to_a
# @yieldparam dir [ComponentDir] the yielded component dir
#
# @api public
def each(&block)
to_a.each(&block)
def each(&)
to_a.each(&)
end

protected
Expand Down Expand Up @@ -272,9 +272,9 @@ def apply_defaults_to_dir(dir)
end
end

def method_missing(name, *args, &block)
def method_missing(name, ...)
if defaults.respond_to?(name)
defaults.public_send(name, *args, &block)
defaults.public_send(name, ...)
else
super
end
Expand Down
4 changes: 2 additions & 2 deletions lib/dry/system/config/namespaces.rb
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ def to_a
# @yieldparam namespace [Namespace] the yielded namespace
#
# @api public
def each(&block)
to_a.each(&block)
def each(&)
to_a.each(&)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/dry/system/container.rb
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ def injector(**options)
# @api public
def require_from_root(*paths)
paths.flat_map { |path|
path.to_s.include?("*") ? ::Dir[root.join(path)].sort : root.join(path)
path.to_s.include?("*") ? ::Dir[root.join(path)] : root.join(path)
}.each { |path|
Kernel.require path.to_s
}
Expand Down
2 changes: 1 addition & 1 deletion lib/dry/system/errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def initialize(component, error,
end
end

super message.join("\n")
super(message.join("\n"))
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/dry/system/manifest_registrar.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def initialize(container)

# @api private
def finalize!
::Dir[registrations_dir.join(RB_GLOB)].sort.each do |file|
::Dir[registrations_dir.join(RB_GLOB)].each do |file|
call(Identifier.new(File.basename(file, RB_EXT)))
end
end
Expand All @@ -38,7 +38,7 @@ def call(component)

# @api private
def file_exists?(component)
File.exist?(File.join(registrations_dir, "#{component.root_key}#{RB_EXT}"))
::File.exist?(::File.join(registrations_dir, "#{component.root_key}#{RB_EXT}"))
end

private
Expand Down
4 changes: 2 additions & 2 deletions lib/dry/system/plugins.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ module Plugins
# @return [Plugins]
#
# @api public
def self.register(name, plugin, &block)
registry[name] = Plugin.new(name, plugin, &block)
def self.register(name, plugin, &)
registry[name] = Plugin.new(name, plugin, &)
end

# @api private
Expand Down
2 changes: 1 addition & 1 deletion lib/dry/system/plugins/dependency_graph.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def injector(**options)
end

# @api private
def register(key, contents = nil, options = {}, &block)
def register(key, contents = nil, options = {}, &)
super.tap do
key = key.to_s

Expand Down
6 changes: 3 additions & 3 deletions lib/dry/system/plugins/dependency_graph/strategies.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def define_initialize(klass)
target_class: klass
)

super(klass)
super
end
end

Expand All @@ -36,7 +36,7 @@ def define_initialize(klass)
target_class: klass
)

super(klass)
super
end
end

Expand All @@ -51,7 +51,7 @@ def define_initialize(klass)
target_class: klass
)

super(klass)
super
end
end

Expand Down
12 changes: 6 additions & 6 deletions lib/dry/system/provider/source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ class << self
def for(name:, group: nil, superclass: nil, &block)
superclass ||= self

Class.new(superclass) { |klass|
::Class.new(superclass) { |klass|
klass.source_name name
klass.source_group group

name_with_group = group ? "#{group}->#{name}" : name
klass.instance_eval <<~RUBY, __FILE__, __LINE__ + 1
def name
"#{superclass.name}[#{name_with_group}]"
end
klass.instance_eval(<<~RUBY, __FILE__, __LINE__ + 1)
def name # def name
"#{superclass.name}[#{name_with_group}]" # "CustomSource[custom]"
end # end
RUBY

SourceDSL.evaluate(klass, &block) if block
Expand Down Expand Up @@ -263,7 +263,7 @@ def run_step_block(step_name)
end

# @api private
def method_missing(name, *args, &block)
def method_missing(name, *args, &)
if container.key?(name)
container[name]
else
Expand Down
20 changes: 10 additions & 10 deletions lib/dry/system/provider/source_dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ class Provider
#
# @api private
class SourceDSL
def self.evaluate(source_class, &block)
new(source_class).instance_eval(&block)
def self.evaluate(source_class, &)
new(source_class).instance_eval(&)
end

attr_reader :source_class
Expand All @@ -24,23 +24,23 @@ def setting(...)
source_class.setting(...)
end

def prepare(&block)
source_class.define_method(:prepare, &block)
def prepare(&)
source_class.define_method(:prepare, &)
end

def start(&block)
source_class.define_method(:start, &block)
def start(&)
source_class.define_method(:start, &)
end

def stop(&block)
source_class.define_method(:stop, &block)
def stop(&)
source_class.define_method(:stop, &)
end

private

def method_missing(name, *args, &block)
def method_missing(name, ...)
if source_class.respond_to?(name)
source_class.public_send(name, *args, &block)
source_class.public_send(name, ...)
else
super
end
Expand Down
4 changes: 2 additions & 2 deletions lib/dry/system/provider_registrar.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,10 @@ def key?(provider_name)
# @api public
def provider_files
@provider_files ||= provider_paths.each_with_object([[], []]) { |path, (provider_files, loaded)| # rubocop:disable Layout/LineLength
files = Dir["#{path}/#{RB_GLOB}"].sort
files = ::Dir["#{path}/#{RB_GLOB}"]

files.each do |file|
basename = File.basename(file)
basename = ::File.basename(file)

unless loaded.include?(basename)
provider_files << Pathname(file)
Expand Down
2 changes: 1 addition & 1 deletion lib/dry/system/provider_source_registry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def initialize
end

def load_sources(path)
Dir[File.join(path, "**/#{RB_GLOB}")].sort.each do |file|
::Dir[::File.join(path, "**/#{RB_GLOB}")].each do |file|
require file
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/dry/system/provider_sources/settings/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ def self.load(root:, env:, loader: Loader)

private

def method_missing(name, *args, &block)
def method_missing(name, ...)
if config.respond_to?(name)
config.public_send(name, *args, &block)
config.public_send(name, ...)
else
super
end
Expand Down
4 changes: 2 additions & 2 deletions lib/dry/system/stubs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ module Stubs
# of the container
#
# @api private
def finalize!(**, &block)
super(freeze: false, &block)
def finalize!(**, &)
super(freeze: false, &)
end
end

Expand Down
16 changes: 8 additions & 8 deletions spec/integration/container/plugins_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,11 @@ def self.dependencies
it "raises exception" do
msg =
if RUBY_ENGINE == "jruby"
"dry-system plugin :test_plugin failed to load its dependencies:"\
" no such file to load -- this-does-not-exist - add gem_name to your Gemfile"
"dry-system plugin :test_plugin failed to load its dependencies: " \
"no such file to load -- this-does-not-exist - add gem_name to your Gemfile"
else
"dry-system plugin :test_plugin failed to load its dependencies:"\
" cannot load such file -- this-does-not-exist - add gem_name to your Gemfile"
"dry-system plugin :test_plugin failed to load its dependencies: " \
"cannot load such file -- this-does-not-exist - add gem_name to your Gemfile"
end

expect { system.use(:test_plugin) }
Expand All @@ -124,11 +124,11 @@ def self.dependencies
it "raises exception" do
msg =
if RUBY_ENGINE == "jruby"
"dry-system plugin :test_plugin failed to load its dependencies:"\
" no such file to load -- this-does-not-exist"
"dry-system plugin :test_plugin failed to load its dependencies: " \
"no such file to load -- this-does-not-exist"
else
"dry-system plugin :test_plugin failed to load its dependencies:"\
" cannot load such file -- this-does-not-exist"
"dry-system plugin :test_plugin failed to load its dependencies: " \
"cannot load such file -- this-does-not-exist"
end

expect { system.use(:test_plugin) }
Expand Down
2 changes: 1 addition & 1 deletion spec/integration/external_components_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ class Container < Dry::System::Container
"Available provider sources:",
"- :logger, group: :external_components"
]
error_re = /#{msgs.join('.*')}/m
error_re = /#{msgs.join(".*")}/m

expect {
Class.new(Dry::System::Container) {
Expand Down
4 changes: 2 additions & 2 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
rescue LoadError; end
SPEC_ROOT = Pathname(__FILE__).dirname

Dir[SPEC_ROOT.join("support/*.rb").to_s].sort.each { |f| require f }
Dir[SPEC_ROOT.join("shared/*.rb").to_s].sort.each { |f| require f }
Dir[SPEC_ROOT.join("support/*.rb").to_s].each { |f| require f }
Dir[SPEC_ROOT.join("shared/*.rb").to_s].each { |f| require f }

require "dry/system"
require "dry/system/stubs"
Expand Down
12 changes: 6 additions & 6 deletions spec/support/tmp_directory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,22 @@ module Support
module TmpDirectory
private

def with_tmp_directory(&block)
with_directory(make_tmp_directory, &block)
def with_tmp_directory(&)
with_directory(make_tmp_directory, &)
end

def with_directory(dir, &block)
Dir.chdir(dir, &block)
def with_directory(dir, &)
Dir.chdir(dir, &)
end

def make_tmp_directory
Pathname(Dir.mktmpdir).tap do |dir|
Pathname(::Dir.mktmpdir).tap do |dir|
(@made_tmp_dirs ||= []) << dir
end
end

def write(path, *content)
Pathname.new(path).dirname.mkpath
::Pathname.new(path).dirname.mkpath

File.open(path, ::File::CREAT | ::File::WRONLY) do |file|
file.write(Array(content).flatten.join)
Expand Down
Loading

0 comments on commit 562394b

Please sign in to comment.