From d2de00f6249d17aea7965573972633677018f4cf Mon Sep 17 00:00:00 2001 From: Nikita Shilnikov Date: Tue, 21 Jan 2025 14:59:26 +0100 Subject: [PATCH] Drop variables and qualify constants Also remove one leftover from 2.7 ruby --- core/lib/rom/attribute.rb | 6 +++++- core/lib/rom/command.rb | 9 +++++++-- core/lib/rom/command_compiler.rb | 4 ++-- core/lib/rom/configuration.rb | 4 ++-- core/lib/rom/data_proxy.rb | 2 +- core/lib/rom/enumerable_dataset.rb | 2 +- core/lib/rom/environment.rb | 10 +++++++--- core/lib/rom/model_builder.rb | 2 +- core/lib/rom/open_struct.rb | 6 +++--- core/lib/rom/registry.rb | 12 ++++-------- core/lib/rom/relation_registry.rb | 2 +- 11 files changed, 34 insertions(+), 25 deletions(-) diff --git a/core/lib/rom/attribute.rb b/core/lib/rom/attribute.rb index ccaf65815..b4543f5ae 100644 --- a/core/lib/rom/attribute.rb +++ b/core/lib/rom/attribute.rb @@ -345,7 +345,11 @@ def to_write_type = type # @api public def optional sum = self.class.new(super, **options) - read? ? sum.meta(read: meta[:read].optional) : sum + if read? + sum.meta(read: meta[:read].optional) + else + sum + end end # @api private diff --git a/core/lib/rom/command.rb b/core/lib/rom/command.rb index dd5c2484a..9bd490f18 100644 --- a/core/lib/rom/command.rb +++ b/core/lib/rom/command.rb @@ -255,7 +255,7 @@ def gateway # @api private def execute(*) raise( - NotImplementedError, + ::NotImplementedError, "#{self.class}##{__method__} must be implemented" ) end @@ -277,7 +277,12 @@ def call(*args, &) apply_hooks(before_hooks, *args) end - result = prepared ? execute(prepared, &) : execute(&) + result = + if prepared + execute(prepared, &) + else + execute(&) + end if curried? if !args.empty? diff --git a/core/lib/rom/command_compiler.rb b/core/lib/rom/command_compiler.rb index c23202f3a..d1b8be5b4 100644 --- a/core/lib/rom/command_compiler.rb +++ b/core/lib/rom/command_compiler.rb @@ -115,7 +115,7 @@ def call(*args) # @api private def type @_type ||= Commands.const_get(Inflector.classify(id))[adapter] - rescue NameError + rescue ::NameError nil end @@ -172,7 +172,7 @@ def visit_relation(node, parent_relation = nil) # rubocop:enable Metrics/AbcSize, Metrics/MethodLength, Metrics/PerceivedComplexity # @api private - def visit_attribute(*_args) = nil + def visit_attribute(*) = nil # Build a command object for a specific relation # diff --git a/core/lib/rom/configuration.rb b/core/lib/rom/configuration.rb index f9868cad9..0ffb62829 100644 --- a/core/lib/rom/configuration.rb +++ b/core/lib/rom/configuration.rb @@ -50,7 +50,7 @@ class Configuration # @return [Configuration] # # @api private - def initialize(*args, &) + def initialize(*args) @environment = Environment.new(*args) @notifications = Notifications.event_bus(:configuration) @setup = Setup.new(notifications) @@ -66,7 +66,7 @@ def initialize(*args, &) # @return [Configuration] # # @api public - def use(plugin, options = {}) + def use(plugin, options = EMPTY_HASH) if plugin.is_a?(::Array) plugin.each { |p| use(p) } elsif plugin.is_a?(::Hash) diff --git a/core/lib/rom/data_proxy.rb b/core/lib/rom/data_proxy.rb index 19fb00d11..0677438e1 100644 --- a/core/lib/rom/data_proxy.rb +++ b/core/lib/rom/data_proxy.rb @@ -33,7 +33,7 @@ def self.included(klass) klass.class_eval do extend ClassMethods - include Dry::Equalizer(:data) + include ::Dry::Equalizer(:data) option :row_proc, default: -> { self.class.row_proc } end diff --git a/core/lib/rom/enumerable_dataset.rb b/core/lib/rom/enumerable_dataset.rb index 610d8aba6..06c3ee89a 100644 --- a/core/lib/rom/enumerable_dataset.rb +++ b/core/lib/rom/enumerable_dataset.rb @@ -43,7 +43,7 @@ module EnumerableDataset # # @api private def self.included(klass) - return unless klass.is_a?(Class) + return unless klass.is_a?(::Class) klass.class_eval do extend Initializer diff --git a/core/lib/rom/environment.rb b/core/lib/rom/environment.rb index 303a7418a..3ce2e6dbb 100644 --- a/core/lib/rom/environment.rb +++ b/core/lib/rom/environment.rb @@ -26,7 +26,7 @@ def initialize(*args) # @api private def configure_gateways(*args) - normalized_gateway_args = normalize_gateway_args(*args) + normalized_gateway_args = normalize_gateway_args(args) normalized_gateways = normalize_gateways(normalized_gateway_args) @gateways, @gateways_map = normalized_gateways.values_at(:gateways, :map) @@ -38,8 +38,12 @@ def configure_gateways(*args) end # @api private - def normalize_gateway_args(*args) - args.first.is_a?(Hash) ? args.first : { default: args } + def normalize_gateway_args(args) + if args.first.is_a?(::Hash) + args.first + else + { default: args } + end end # Build gateways using the setup interface diff --git a/core/lib/rom/model_builder.rb b/core/lib/rom/model_builder.rb index 0b78867c3..c4b0a8f1b 100644 --- a/core/lib/rom/model_builder.rb +++ b/core/lib/rom/model_builder.rb @@ -60,7 +60,7 @@ def initialize(options = {}) if parts.any? Inflector.constantize(parts.join('::')) else - Object + ::Object end end end diff --git a/core/lib/rom/open_struct.rb b/core/lib/rom/open_struct.rb index 33a5427a1..d4002e784 100644 --- a/core/lib/rom/open_struct.rb +++ b/core/lib/rom/open_struct.rb @@ -18,16 +18,16 @@ def initialize(attributes) # @api private def respond_to_missing?(meth, include_private = false) - super || instance_variables.include?(IVAR[meth]) + instance_variable_defined?(IVAR[meth]) || super end private # @api private - def method_missing(meth, *args, &) + def method_missing(meth, *, &) ivar = IVAR[meth] - if instance_variables.include?(ivar) + if instance_variable_defined?(ivar) instance_variable_get(ivar) else super diff --git a/core/lib/rom/registry.rb b/core/lib/rom/registry.rb index 8ed4c5682..9dda23116 100644 --- a/core/lib/rom/registry.rb +++ b/core/lib/rom/registry.rb @@ -22,18 +22,14 @@ class Registry option :cache, default: -> { Cache.new } # @api private - def self.new(*args, **kwargs) - if args.empty? && kwargs.empty? - super({}, **{}) - else - super - end + def self.new(elements = {}, *, **) + super end # Create a registry without options # # @api private - def self.build(elements = {}) = new(elements, **{}) + def self.build(elements = {}) = new(elements) # @api private def self.[](identifier) @@ -78,7 +74,7 @@ def key?(name) = !name.nil? && elements.key?(name.to_sym) # @api private def fetch(key) - raise ArgumentError, 'key cannot be nil' if key.nil? + raise ::ArgumentError, 'key cannot be nil' if key.nil? elements.fetch(key.to_sym) do return yield if block_given? diff --git a/core/lib/rom/relation_registry.rb b/core/lib/rom/relation_registry.rb index f630ef185..e4ef55304 100644 --- a/core/lib/rom/relation_registry.rb +++ b/core/lib/rom/relation_registry.rb @@ -6,7 +6,7 @@ module ROM # @api private class RelationRegistry < Registry # @api private - def initialize(elements = {}, **options) + def initialize(elements = {}, **) super yield(self, elements) if block_given? end