Skip to content

Commit

Permalink
Add :: everywhere where ambiguity may occur
Browse files Browse the repository at this point in the history
  • Loading branch information
flash-gordon committed Jan 3, 2025
1 parent ccd791b commit b4c723a
Show file tree
Hide file tree
Showing 13 changed files with 33 additions and 30 deletions.
8 changes: 4 additions & 4 deletions lib/dry/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ module Core
include Constants

def self.loader
@loader ||= Zeitwerk::Loader.new.tap do |loader|
root = File.expand_path("..", __dir__)
@loader ||= ::Zeitwerk::Loader.new.tap do |loader|
root = ::File.expand_path("..", __dir__)
loader.tag = "dry-core"
loader.inflector = Zeitwerk::GemInflector.new("#{root}/dry-core.rb")
loader.inflector = ::Zeitwerk::GemInflector.new("#{root}/dry-core.rb")
loader.push_dir(root)
loader.ignore(
"#{root}/dry-core.rb",
Expand Down Expand Up @@ -50,7 +50,7 @@ def self.Equalizer(*keys, **options)
#
# @api public
def self.Equalizer(*keys, **options)
Dry::Core::Equalizer.new(*keys, **options)
::Dry::Core::Equalizer.new(*keys, **options)
end
end
end
2 changes: 1 addition & 1 deletion lib/dry/core/cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module Cache
def self.extended(klass)
super
klass.include(Methods)
klass.instance_variable_set(:@__cache__, Concurrent::Map.new)
klass.instance_variable_set(:@__cache__, ::Concurrent::Map.new)
end

# @api private
Expand Down
10 changes: 5 additions & 5 deletions lib/dry/core/class_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ module Dry
module Core
# Class for generating more classes
class ClassBuilder
ParentClassMismatch = Class.new(TypeError)
ParentClassMismatch = ::Class.new(::TypeError)

attr_reader :name, :parent, :namespace

def initialize(name:, parent: nil, namespace: nil)
@name = name
@namespace = namespace
@parent = parent || Object
@parent = parent || ::Object
end

# Generate a class based on options
Expand Down Expand Up @@ -48,7 +48,7 @@ def call

# @api private
def create_anonymous
klass = Class.new(parent)
klass = ::Class.new(parent)
name = self.name

klass.singleton_class.class_eval do
Expand All @@ -64,7 +64,7 @@ def create_anonymous
def create_named
name = self.name
base = create_base(namespace, name, parent)
klass = Class.new(base)
klass = ::Class.new(base)

namespace.module_eval do
remove_const(name)
Expand Down Expand Up @@ -93,7 +93,7 @@ def create_base(namespace, name, parent)

existing
else
klass = Class.new(parent || Object)
klass = ::Class.new(parent || ::Object)
namespace.const_set(name, klass)
klass
end
Expand Down
2 changes: 1 addition & 1 deletion lib/dry/core/constants.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ module Constants
# puts value
# end
# end
Undefined = Object.new.tap do |undefined|
Undefined = ::Object.new.tap do |undefined|
# @api private
Self = -> { Undefined } # rubocop:disable Lint/ConstantDefinitionInBlock

Expand Down
11 changes: 7 additions & 4 deletions lib/dry/core/container/item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,26 @@ class Container
# @api abstract
#
class Item
NO_OPTIONS = {}.freeze

# @return [Mixed] the item to be solved later
attr_reader :item

# @return [Hash] the options to memoize, call or no.
attr_reader :options

# @api abstract
def initialize(item, options = {})
def initialize(item, options = NO_OPTIONS)
@item = item
@options = {
call: item.is_a?(::Proc) && item.parameters.empty?
}.merge(options)
call: item.is_a?(::Proc) && item.parameters.empty?,
**options
}
end

# @api abstract
def call
raise NotImplementedError
raise ::NotImplementedError
end

# @private
Expand Down
10 changes: 5 additions & 5 deletions lib/dry/core/container/mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@
module Dry
module Core
class Container
include Dry::Core::Constants
include ::Dry::Core::Constants

# @api public
Error = Class.new(StandardError)
Error = ::Class.new(::StandardError)

# Error raised when key is not defined in the registry
#
# @api public
KeyError = Class.new(::KeyError)
KeyError = ::Class.new(::KeyError)

if defined?(DidYouMean::KeyErrorChecker)
DidYouMean.correct_error(KeyError, DidYouMean::KeyErrorChecker)
if defined?(::DidYouMean::KeyErrorChecker)
::DidYouMean.correct_error(KeyError, ::DidYouMean::KeyErrorChecker)
end

# Mixin to expose Inversion of Control (IoC) container behaviour
Expand Down
2 changes: 1 addition & 1 deletion lib/dry/core/container/stub.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def resolve(key)
# Add a stub to the container
def stub(key, value, &block)
unless key?(key)
raise ArgumentError, "cannot stub #{key.to_s.inspect} - no such key in container"
raise ::ArgumentError, "cannot stub #{key.to_s.inspect} - no such key in container"
end

_stubs[key.to_s] = value
Expand Down
2 changes: 1 addition & 1 deletion lib/dry/core/deprecations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def deprecate_constant(constant_name, message: nil)
message
)

mod = Module.new do
mod = ::Module.new do
define_method(:const_missing) do |missing|
if missing == constant_name
warn("#{full_msg}\n#{STACK.()}")
Expand Down
2 changes: 1 addition & 1 deletion lib/dry/core/descendants_tracker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ module DescendantsTracker
class << self
# @api private
def setup(target)
target.instance_variable_set(:@descendants, Concurrent::Array.new)
target.instance_variable_set(:@descendants, ::Concurrent::Array.new)
end

private
Expand Down
2 changes: 1 addition & 1 deletion lib/dry/core/equalizer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def ==(other)
#
# @api public
def self.Equalizer(*keys, **options)
Dry::Core::Equalizer.new(*keys, **options)
::Dry::Core::Equalizer.new(*keys, **options)
end
end
end
2 changes: 1 addition & 1 deletion lib/dry/core/errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module Dry
module Core
class InvalidClassAttributeValueError < StandardError
class InvalidClassAttributeValueError < ::StandardError
def initialize(name, value)
super(
"Value #{value.inspect} is invalid for class attribute #{name.inspect}"
Expand Down
4 changes: 2 additions & 2 deletions lib/dry/core/extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module Extensions
def self.extended(obj)
super
obj.instance_variable_set(:@__available_extensions__, {})
obj.instance_variable_set(:@__loaded_extensions__, Set.new)
obj.instance_variable_set(:@__loaded_extensions__, ::Set.new)
end

# Register an extension
Expand All @@ -50,7 +50,7 @@ def available_extension?(name)
def load_extensions(*extensions)
extensions.each do |ext|
block = @__available_extensions__.fetch(ext) do
raise ArgumentError, "Unknown extension: #{ext.inspect}"
raise ::ArgumentError, "Unknown extension: #{ext.inspect}"
end
unless @__loaded_extensions__.include?(ext)
block.call
Expand Down
6 changes: 3 additions & 3 deletions lib/dry/core/inflector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module Inflector
],
dry_inflector: [
"dry/inflector",
proc { Dry::Inflector.new }
proc { ::Dry::Inflector.new }
],
inflecto: [
"inflecto",
Expand All @@ -25,7 +25,7 @@ module Inflector
# @api private
def self.realize_backend(path, backend_factory)
require path
rescue LoadError
rescue ::LoadError
nil
else
backend_factory.call
Expand All @@ -49,7 +49,7 @@ def self.detect_backend
# @param [Symbol] name backend name (:activesupport or :inflecto)
def self.select_backend(name = nil)
if name && !BACKENDS.key?(name)
raise NameError, "Invalid inflector library selection: '#{name}'"
raise ::NameError, "Invalid inflector library selection: '#{name}'"
end

@inflector = name ? realize_backend(*BACKENDS[name]) : detect_backend
Expand Down

0 comments on commit b4c723a

Please sign in to comment.