Skip to content

Commit

Permalink
Use :: for referencing top-level constants
Browse files Browse the repository at this point in the history
  • Loading branch information
flash-gordon committed Jan 3, 2025
1 parent 572958a commit d91b862
Show file tree
Hide file tree
Showing 31 changed files with 101 additions and 101 deletions.
8 changes: 4 additions & 4 deletions lib/dry/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ module Dry
#
# @api public
module Schema
extend Dry::Core::Extensions
extend ::Dry::Core::Extensions

# @api private
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-schema"
loader.inflector = Zeitwerk::GemInflector.new("#{root}/dry-schema.rb")
loader.inflector = ::Zeitwerk::GemInflector.new("#{root}/dry-schema.rb")
loader.inflector.inflect(
"dsl" => "DSL",
"yaml" => "YAML",
Expand Down
8 changes: 4 additions & 4 deletions lib/dry/schema/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ module Schema
#
# @api public
class Config
include Dry::Configurable
include Dry::Equalizer(:to_h, inspect: false)
include ::Dry::Configurable
include ::Dry::Equalizer(:to_h, inspect: false)

# @!method predicates
#
Expand All @@ -33,7 +33,7 @@ class Config
# @return [Hash]
#
# @api public
setting :types, default: Dry::Types
setting :types, default: ::Dry::Types

# @!method messages
#
Expand All @@ -45,7 +45,7 @@ class Config
setting :messages do
setting :backend, default: :yaml
setting :namespace
setting :load_paths, default: Set[DEFAULT_MESSAGES_PATH], constructor: :dup.to_proc
setting :load_paths, default: ::Set[DEFAULT_MESSAGES_PATH], constructor: :dup.to_proc
setting :top_namespace, default: DEFAULT_MESSAGES_ROOT
setting :default_locale
end
Expand Down
4 changes: 2 additions & 2 deletions lib/dry/schema/constants.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ module Schema
DEFAULT_MESSAGES_ROOT = "dry_schema"

# An error raised when DSL is used in an incorrect way
InvalidSchemaError = Class.new(StandardError)
InvalidSchemaError = ::Class.new(::StandardError)

# An error raised when a localized message cannot be found
MissingMessageError = Class.new(StandardError) do
MissingMessageError = ::Class.new(::StandardError) do
# @api private
def initialize(path, paths = [])
*rest, rule = path
Expand Down
4 changes: 2 additions & 2 deletions lib/dry/schema/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ module Schema
class DSL
Types = Schema::Types

extend Dry::Initializer
extend ::Dry::Initializer

# @return [Compiler] The type of the processor (Params, JSON, or a custom sub-class)
option :processor_type, default: -> { Processor }
Expand Down Expand Up @@ -501,7 +501,7 @@ def parent_key_map
def default_config
parents.each_cons(2) do |left, right|
unless left.config == right.config
raise ArgumentError,
raise ::ArgumentError,
"Parent configs differ, left=#{left.inspect}, right=#{right.inspect}"
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/dry/schema/extensions/json_schema/schema_compiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module JSONSchema
# @api private
class SchemaCompiler
# An error raised when a predicate cannot be converted
UnknownConversionError = Class.new(StandardError)
UnknownConversionError = ::Class.new(::StandardError)

IDENTITY = ->(v, _) { v }.freeze
TO_INTEGER = ->(v, _) { v.to_i }.freeze
Expand Down
2 changes: 1 addition & 1 deletion lib/dry/schema/extensions/monads.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module Schema
#
# @api public
class Result
include Dry::Monads::Result::Mixin
include ::Dry::Monads::Result::Mixin

# Turn result into a monad
#
Expand Down
8 changes: 4 additions & 4 deletions lib/dry/schema/key.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ module Schema
#
# @api public
class Key
extend Dry::Core::Cache
extend ::Dry::Core::Cache

DEFAULT_COERCER = :itself.to_proc.freeze

include Dry.Equalizer(:name, :coercer)
include ::Dry.Equalizer(:name, :coercer)

# @return [Symbol] The key identifier
attr_reader :id
Expand Down Expand Up @@ -90,7 +90,7 @@ def coerced_name
#
# @api private
class Hash < self
include Dry.Equalizer(:name, :members, :coercer)
include ::Dry.Equalizer(:name, :members, :coercer)

# @api private
attr_reader :members
Expand Down Expand Up @@ -137,7 +137,7 @@ def dump
#
# @api private
class Array < self
include Dry.Equalizer(:name, :member, :coercer)
include ::Dry.Equalizer(:name, :member, :coercer)

attr_reader :member

Expand Down
2 changes: 1 addition & 1 deletion lib/dry/schema/key_coercer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module Schema
#
# @api private
class KeyCoercer
extend Dry::Core::Cache
extend ::Dry::Core::Cache
include ::Dry::Equalizer(:key_map, :coercer)

TO_SYM = :to_sym.to_proc.freeze
Expand Down
6 changes: 3 additions & 3 deletions lib/dry/schema/key_map.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ module Schema
#
# @api public
class KeyMap
extend Dry::Core::Cache
extend ::Dry::Core::Cache

include Dry.Equalizer(:keys)
include Enumerable
include ::Dry.Equalizer(:keys)
include ::Enumerable

# @return [Array<Key>] A list of defined key objects
attr_reader :keys
Expand Down
2 changes: 1 addition & 1 deletion lib/dry/schema/key_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module Dry
module Schema
# @api private
class KeyValidator
extend Dry::Initializer
extend ::Dry::Initializer

INDEX_REGEX = /\[\d+\]/
DIGIT_REGEX = /\A\d+\z/
Expand Down
2 changes: 1 addition & 1 deletion lib/dry/schema/macros/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module Macros
#
# @api public
class DSL < Core
include Dry::Logic::Operators
include ::Dry::Logic::Operators

undef :eql?
undef :nil?
Expand Down
8 changes: 4 additions & 4 deletions lib/dry/schema/message.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ module Schema
#
# @api public
class Message
include Dry::Equalizer(:text, :path, :predicate, :input)
include ::Dry::Equalizer(:text, :path, :predicate, :input)

extend Dry::Initializer
extend ::Dry::Initializer

# @!attribute [r] text
# Message text representation created from a localized template
Expand Down Expand Up @@ -75,7 +75,7 @@ def to_h
#
# @api private
def eql?(other)
other.is_a?(String) ? text == other : super
other.is_a?(::String) ? text == other : super
end

# @api private
Expand All @@ -94,7 +94,7 @@ def <=>(other)
r_path = other._path

unless l_path.same_root?(r_path)
raise ArgumentError, "Cannot compare messages from different root paths"
raise ::ArgumentError, "Cannot compare messages from different root paths"
end

l_path <=> r_path
Expand Down
12 changes: 6 additions & 6 deletions lib/dry/schema/message_compiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module Schema
#
# @api private
class MessageCompiler
extend Dry::Initializer
extend ::Dry::Initializer

resolve_key_predicate = proc { |node, opts|
*arg_vals, val = node.map(&:last)
Expand All @@ -20,12 +20,12 @@ class MessageCompiler
[Array(opts.path), *node.map(&:last)]
}

DEFAULT_PREDICATE_RESOLVERS = Hash
DEFAULT_PREDICATE_RESOLVERS = ::Hash
.new(resolve_predicate).update(key?: resolve_key_predicate).freeze

EMPTY_OPTS = VisitorOpts.new
EMPTY_MESSAGE_SET = MessageSet.new(EMPTY_ARRAY).freeze
FULL_MESSAGE_WHITESPACE = Hash.new(" ").merge(
FULL_MESSAGE_WHITESPACE = ::Hash.new(" ").merge(
ja: "",
zh: "",
bn: "",
Expand Down Expand Up @@ -190,7 +190,7 @@ def visit_xor(node, opts)
def lookup_options(arg_vals:, input:)
default_lookup_options.merge(
arg_type: arg_vals.size == 1 && arg_vals[0].class,
val_type: input.equal?(Undefined) ? NilClass : input.class
val_type: input.equal?(Undefined) ? ::NilClass : input.class
)
end

Expand All @@ -209,9 +209,9 @@ def message_text(template, tokens, options)
def message_tokens(args)
tokens = args.each_with_object({}) do |arg, hash|
case arg[1]
when Array
when ::Array
hash[arg[0]] = arg[1].join(LIST_SEPARATOR)
when Range
when ::Range
hash["#{arg[0]}_left".to_sym] = arg[1].first
hash["#{arg[0]}_right".to_sym] = arg[1].last
else
Expand Down
10 changes: 5 additions & 5 deletions lib/dry/schema/message_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ module Schema
#
# @api public
class MessageSet
include Enumerable
include Dry::Equalizer(:messages, :options)
include ::Enumerable
include ::Dry::Equalizer(:messages, :options)

# A list of compiled message objects
#
Expand Down Expand Up @@ -82,7 +82,7 @@ def [](key)
#
# @api public
def fetch(key)
self[key] || raise(KeyError, "+#{key}+ message was not found")
self[key] || raise(::KeyError, "+#{key}+ message was not found")
end

# Check if a message set is empty
Expand Down Expand Up @@ -135,9 +135,9 @@ def combine_message_values(values)
# @api private
def partition_message_values(values)
values
.map { |value| value.is_a?(Array) ? value : [value] }
.map { |value| value.is_a?(::Array) ? value : [value] }
.reduce(EMPTY_ARRAY.dup, :+)
.partition { |value| value.is_a?(Hash) && !value[:text].is_a?(String) }
.partition { |value| value.is_a?(::Hash) && !value[:text].is_a?(::String) }
end
end
end
Expand Down
24 changes: 12 additions & 12 deletions lib/dry/schema/messages/abstract.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ module Messages
#
# @api public
class Abstract
include Dry::Configurable
include Dry::Equalizer(:config)
include ::Dry::Configurable
include ::Dry::Equalizer(:config)

setting :default_locale
setting :load_paths, default: Set[DEFAULT_MESSAGES_PATH]
setting :load_paths, default: ::Set[DEFAULT_MESSAGES_PATH]
setting :top_namespace, default: DEFAULT_MESSAGES_ROOT
setting :root, default: "errors"
setting :lookup_options, default: %i[root predicate path val_type arg_type].freeze
Expand All @@ -34,13 +34,13 @@ class Abstract

setting :rule_lookup_paths, default: ["rules.%<name>s"].freeze

setting :arg_types, default: Hash.new { |*| "default" }.update(
Range => "range"
setting :arg_types, default: ::Hash.new { |*| "default" }.update(
::Range => "range"
)

setting :val_types, default: Hash.new { |*| "default" }.update(
Range => "range",
String => "string"
setting :val_types, default: ::Hash.new { |*| "default" }.update(
::Range => "range",
::String => "string"
)

# @api private
Expand Down Expand Up @@ -80,7 +80,7 @@ def rule(name, options = {})
path = rule_lookup_paths(tokens).detect { |key| key?(key, options) }

rule = get(path, options) if path
rule.is_a?(Hash) ? rule[:text] : rule
rule.is_a?(::Hash) ? rule[:text] : rule
end

# Retrieve a message template
Expand Down Expand Up @@ -115,7 +115,7 @@ def call(predicate, options)
#
# @api public
def key?(_key, _options = EMPTY_HASH)
raise NotImplementedError
raise ::NotImplementedError
end

# Retrieve an array of looked up paths
Expand Down Expand Up @@ -172,12 +172,12 @@ def default_locale

# @api private
def interpolatable_data(_key, _options, **_data)
raise NotImplementedError
raise ::NotImplementedError
end

# @api private
def interpolate(_key, _options, **_data)
raise NotImplementedError
raise ::NotImplementedError
end

private
Expand Down
2 changes: 1 addition & 1 deletion lib/dry/schema/messages/namespaced.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Messages
# Namespaced messages backend
#
# @api public
class Namespaced < Dry::Schema::Messages::Abstract
class Namespaced < ::Dry::Schema::Messages::Abstract
# @api private
attr_reader :namespace

Expand Down
4 changes: 2 additions & 2 deletions lib/dry/schema/messages/template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ module Schema
module Messages
# @api private
class Template
extend Dry::Initializer
include Dry::Equalizer(:messages, :key, :options)
extend ::Dry::Initializer
include ::Dry::Equalizer(:messages, :key, :options)

option :messages
option :key
Expand Down
2 changes: 1 addition & 1 deletion lib/dry/schema/messages/yaml.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module Messages
class YAML < Abstract
LOCALE_TOKEN = "%<locale>s"
TOKEN_REGEXP = /%{(\w*)}/
EMPTY_CONTEXT = Object.new.tap { |ctx|
EMPTY_CONTEXT = ::Object.new.tap { |ctx|
def ctx.context
binding
end
Expand Down
Loading

0 comments on commit d91b862

Please sign in to comment.