brew vendor-gems: commit updates.
This commit is contained in:
parent
9ba75c3bc5
commit
69feb81a50
@ -24,7 +24,7 @@ $:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/coderay-1.1.3/lib"
|
||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/highline-2.0.3/lib"
|
||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/commander-4.6.0/lib"
|
||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/connection_pool-2.2.5/lib"
|
||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/did_you_mean-1.5.0/lib"
|
||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/did_you_mean-1.6.1/lib"
|
||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/diff-lcs-1.4.4/lib"
|
||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/docile-1.4.0/lib"
|
||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/extensions/x86_64-darwin-14/2.6.0-static/unf_ext-0.0.8"
|
||||
|
||||
@ -1,25 +0,0 @@
|
||||
module DidYouMean
|
||||
module Correctable
|
||||
def original_message
|
||||
method(:to_s).super_method.call
|
||||
end
|
||||
|
||||
def to_s
|
||||
msg = super.dup
|
||||
suggestion = DidYouMean.formatter.message_for(corrections)
|
||||
|
||||
msg << suggestion if !msg.end_with?(suggestion)
|
||||
msg
|
||||
rescue
|
||||
super
|
||||
end
|
||||
|
||||
def corrections
|
||||
@corrections ||= spell_checker.corrections
|
||||
end
|
||||
|
||||
def spell_checker
|
||||
SPELL_CHECKERS[self.class.to_s].new(self)
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -1,49 +0,0 @@
|
||||
# frozen-string-literal: true
|
||||
|
||||
module DidYouMean
|
||||
# The +DidYouMean::VerboseFormatter+ uses extra empty lines to make the
|
||||
# suggestion stand out more in the error message.
|
||||
#
|
||||
# In order to activate the verbose formatter,
|
||||
#
|
||||
# @example
|
||||
#
|
||||
# OBject
|
||||
# # => NameError: uninitialized constant OBject
|
||||
# # Did you mean? Object
|
||||
#
|
||||
# require 'did_you_mean/verbose'
|
||||
#
|
||||
# OBject
|
||||
# # => NameError: uninitialized constant OBject
|
||||
# #
|
||||
# # Did you mean? Object
|
||||
# #
|
||||
#
|
||||
class VerboseFormatter
|
||||
|
||||
# Returns a human readable string that contains +corrections+. This
|
||||
# formatter is designed to be less verbose to not take too much screen
|
||||
# space while being helpful enough to the user.
|
||||
#
|
||||
# @example
|
||||
#
|
||||
# formatter = DidYouMean::PlainFormatter.new
|
||||
#
|
||||
# puts formatter.message_for(["methods", "method"])
|
||||
#
|
||||
#
|
||||
# Did you mean? methods
|
||||
# method
|
||||
#
|
||||
# # => nil
|
||||
#
|
||||
def message_for(corrections)
|
||||
return "" if corrections.empty?
|
||||
|
||||
output = "\n\n Did you mean? ".dup
|
||||
output << corrections.join("\n ")
|
||||
output << "\n "
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -1,4 +0,0 @@
|
||||
require_relative '../did_you_mean'
|
||||
require_relative 'formatters/verbose_formatter'
|
||||
|
||||
DidYouMean.formatter = DidYouMean::VerboseFormatter.new
|
||||
@ -1,3 +0,0 @@
|
||||
module DidYouMean
|
||||
VERSION = "1.5.0"
|
||||
end
|
||||
@ -7,7 +7,8 @@ require_relative 'did_you_mean/spell_checkers/method_name_checker'
|
||||
require_relative 'did_you_mean/spell_checkers/key_error_checker'
|
||||
require_relative 'did_you_mean/spell_checkers/null_checker'
|
||||
require_relative 'did_you_mean/spell_checkers/require_path_checker'
|
||||
require_relative 'did_you_mean/formatters/plain_formatter'
|
||||
require_relative 'did_you_mean/spell_checkers/pattern_key_name_checker'
|
||||
require_relative 'did_you_mean/formatter'
|
||||
require_relative 'did_you_mean/tree_spell_checker'
|
||||
|
||||
# The +DidYouMean+ gem adds functionality to suggest possible method/class
|
||||
@ -85,28 +86,70 @@ require_relative 'did_you_mean/tree_spell_checker'
|
||||
#
|
||||
module DidYouMean
|
||||
# Map of error types and spell checker objects.
|
||||
SPELL_CHECKERS = Hash.new(NullChecker)
|
||||
@spell_checkers = Hash.new(NullChecker)
|
||||
|
||||
# Returns a sharable hash map of error types and spell checker objects.
|
||||
def self.spell_checkers
|
||||
@spell_checkers
|
||||
end
|
||||
|
||||
# Adds +DidYouMean+ functionality to an error using a given spell checker
|
||||
def self.correct_error(error_class, spell_checker)
|
||||
SPELL_CHECKERS[error_class.name] = spell_checker
|
||||
error_class.prepend(Correctable) unless error_class < Correctable
|
||||
if defined?(Ractor)
|
||||
new_mapping = { **@spell_checkers, error_class.to_s => spell_checker }
|
||||
new_mapping.default = NullChecker
|
||||
|
||||
@spell_checkers = Ractor.make_shareable(new_mapping)
|
||||
else
|
||||
spell_checkers[error_class.to_s] = spell_checker
|
||||
end
|
||||
|
||||
error_class.prepend(Correctable) if error_class.is_a?(Class) && !(error_class < Correctable)
|
||||
end
|
||||
|
||||
correct_error NameError, NameErrorCheckers
|
||||
correct_error KeyError, KeyErrorChecker
|
||||
correct_error NoMethodError, MethodNameChecker
|
||||
correct_error LoadError, RequirePathChecker if RUBY_VERSION >= '2.8.0'
|
||||
correct_error NoMatchingPatternKeyError, PatternKeyNameChecker if defined?(::NoMatchingPatternKeyError)
|
||||
|
||||
# TODO: Remove on 3.3:
|
||||
class DeprecatedMapping # :nodoc:
|
||||
def []=(key, value)
|
||||
warn "Calling `DidYouMean::SPELL_CHECKERS[#{key.to_s}] = #{value.to_s}' has been deprecated. " \
|
||||
"Please call `DidYouMean.correct_error(#{key.to_s}, #{value.to_s})' instead."
|
||||
|
||||
DidYouMean.correct_error(key, value)
|
||||
end
|
||||
|
||||
def merge!(hash)
|
||||
warn "Calling `DidYouMean::SPELL_CHECKERS.merge!(error_name => spell_checker)' has been deprecated. " \
|
||||
"Please call `DidYouMean.correct_error(error_name, spell_checker)' instead."
|
||||
|
||||
hash.each do |error_class, spell_checker|
|
||||
DidYouMean.correct_error(error_class, spell_checker)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# TODO: Remove on 3.3:
|
||||
SPELL_CHECKERS = DeprecatedMapping.new
|
||||
deprecate_constant :SPELL_CHECKERS
|
||||
private_constant :DeprecatedMapping
|
||||
|
||||
# Returns the currently set formatter. By default, it is set to +DidYouMean::Formatter+.
|
||||
def self.formatter
|
||||
@@formatter
|
||||
if defined?(Ractor)
|
||||
Ractor.current[:__did_you_mean_formatter__] || Formatter
|
||||
else
|
||||
Formatter
|
||||
end
|
||||
end
|
||||
|
||||
# Updates the primary formatter used to format the suggestions.
|
||||
def self.formatter=(formatter)
|
||||
@@formatter = formatter
|
||||
if defined?(Ractor)
|
||||
Ractor.current[:__did_you_mean_formatter__] = formatter
|
||||
end
|
||||
end
|
||||
|
||||
self.formatter = PlainFormatter.new
|
||||
end
|
||||
@ -0,0 +1,32 @@
|
||||
module DidYouMean
|
||||
module Correctable
|
||||
SKIP_TO_S_FOR_SUPER_LOOKUP = true
|
||||
private_constant :SKIP_TO_S_FOR_SUPER_LOOKUP
|
||||
|
||||
def original_message
|
||||
meth = method(:to_s)
|
||||
while meth.owner.const_defined?(:SKIP_TO_S_FOR_SUPER_LOOKUP)
|
||||
meth = meth.super_method
|
||||
end
|
||||
meth.call
|
||||
end
|
||||
|
||||
def to_s
|
||||
msg = super.dup
|
||||
suggestion = DidYouMean.formatter.message_for(corrections)
|
||||
|
||||
msg << suggestion if !msg.include?(suggestion)
|
||||
msg
|
||||
rescue
|
||||
super
|
||||
end
|
||||
|
||||
def corrections
|
||||
@corrections ||= spell_checker.corrections
|
||||
end
|
||||
|
||||
def spell_checker
|
||||
DidYouMean.spell_checkers[self.class.to_s].new(self)
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -1,10 +1,10 @@
|
||||
# frozen-string-literal: true
|
||||
|
||||
module DidYouMean
|
||||
# The +DidYouMean::PlainFormatter+ is the basic, default formatter for the
|
||||
# The +DidYouMean::Formatter+ is the basic, default formatter for the
|
||||
# gem. The formatter responds to the +message_for+ method and it returns a
|
||||
# human readable string.
|
||||
class PlainFormatter
|
||||
class Formatter
|
||||
|
||||
# Returns a human readable string that contains +corrections+. This
|
||||
# formatter is designed to be less verbose to not take too much screen
|
||||
@ -12,7 +12,7 @@ module DidYouMean
|
||||
#
|
||||
# @example
|
||||
#
|
||||
# formatter = DidYouMean::PlainFormatter.new
|
||||
# formatter = DidYouMean::Formatter.new
|
||||
#
|
||||
# # displays suggestions in two lines with the leading empty line
|
||||
# puts formatter.message_for(["methods", "method"])
|
||||
@ -26,8 +26,19 @@ module DidYouMean
|
||||
#
|
||||
# # => nil
|
||||
#
|
||||
def message_for(corrections)
|
||||
def self.message_for(corrections)
|
||||
corrections.empty? ? "" : "\nDid you mean? #{corrections.join("\n ")}"
|
||||
end
|
||||
|
||||
def message_for(corrections)
|
||||
warn "The instance method #message_for has been deprecated. Please use the class method " \
|
||||
"DidYouMean::Formatter.message_for(...) instead."
|
||||
|
||||
self.class.message_for(corrections)
|
||||
end
|
||||
end
|
||||
|
||||
PlainFormatter = Formatter
|
||||
|
||||
deprecate_constant :PlainFormatter
|
||||
end
|
||||
@ -0,0 +1,4 @@
|
||||
require_relative '../formatter'
|
||||
|
||||
warn "`require 'did_you_mean/formatters/plain_formatter'` is deprecated. Please `require 'did_you_mean/formatter'` " \
|
||||
"instead."
|
||||
@ -0,0 +1,9 @@
|
||||
warn "`require 'did_you_mean/formatters/verbose_formatter'` is deprecated and falls back to the default formatter. "
|
||||
|
||||
require_relative '../formatter'
|
||||
|
||||
# frozen-string-literal: true
|
||||
module DidYouMean
|
||||
# For compatibility:
|
||||
VerboseFormatter = Formatter
|
||||
end
|
||||
@ -10,25 +10,25 @@ module DidYouMean
|
||||
end
|
||||
|
||||
def correct(input)
|
||||
input = normalize(input)
|
||||
threshold = input.length > 3 ? 0.834 : 0.77
|
||||
normalized_input = normalize(input)
|
||||
threshold = normalized_input.length > 3 ? 0.834 : 0.77
|
||||
|
||||
words = @dictionary.select { |word| JaroWinkler.distance(normalize(word), input) >= threshold }
|
||||
words.reject! { |word| input == word.to_s }
|
||||
words.sort_by! { |word| JaroWinkler.distance(word.to_s, input) }
|
||||
words = @dictionary.select { |word| JaroWinkler.distance(normalize(word), normalized_input) >= threshold }
|
||||
words.reject! { |word| input.to_s == word.to_s }
|
||||
words.sort_by! { |word| JaroWinkler.distance(word.to_s, normalized_input) }
|
||||
words.reverse!
|
||||
|
||||
# Correct mistypes
|
||||
threshold = (input.length * 0.25).ceil
|
||||
corrections = words.select { |c| Levenshtein.distance(normalize(c), input) <= threshold }
|
||||
threshold = (normalized_input.length * 0.25).ceil
|
||||
corrections = words.select { |c| Levenshtein.distance(normalize(c), normalized_input) <= threshold }
|
||||
|
||||
# Correct misspells
|
||||
if corrections.empty?
|
||||
corrections = words.select do |word|
|
||||
word = normalize(word)
|
||||
length = input.length < word.length ? input.length : word.length
|
||||
length = normalized_input.length < word.length ? normalized_input.length : word.length
|
||||
|
||||
Levenshtein.distance(word, input) < length
|
||||
Levenshtein.distance(word, normalized_input) < length
|
||||
end.first(1)
|
||||
end
|
||||
|
||||
@ -6,6 +6,7 @@ module DidYouMean
|
||||
|
||||
NAMES_TO_EXCLUDE = { NilClass => nil.methods }
|
||||
NAMES_TO_EXCLUDE.default = []
|
||||
Ractor.make_shareable(NAMES_TO_EXCLUDE) if defined?(Ractor)
|
||||
|
||||
# +MethodNameChecker::RB_RESERVED_WORDS+ is the list of reserved words in
|
||||
# Ruby that take an argument. Unlike
|
||||
@ -36,6 +37,8 @@ module DidYouMean
|
||||
yield
|
||||
)
|
||||
|
||||
Ractor.make_shareable(RB_RESERVED_WORDS) if defined?(Ractor)
|
||||
|
||||
def initialize(exception)
|
||||
@method_name = exception.name
|
||||
@receiver = exception.receiver
|
||||
@ -8,6 +8,7 @@ module DidYouMean
|
||||
|
||||
NAMES_TO_EXCLUDE = { 'foo' => [:fork, :for] }
|
||||
NAMES_TO_EXCLUDE.default = []
|
||||
Ractor.make_shareable(NAMES_TO_EXCLUDE) if defined?(Ractor)
|
||||
|
||||
# +VariableNameChecker::RB_RESERVED_WORDS+ is the list of all reserved
|
||||
# words in Ruby. They could be declared like methods are, and a typo would
|
||||
@ -62,6 +63,8 @@ module DidYouMean
|
||||
__ENCODING__
|
||||
)
|
||||
|
||||
Ractor.make_shareable(RB_RESERVED_WORDS) if defined?(Ractor)
|
||||
|
||||
def initialize(exception)
|
||||
@name = exception.name.to_s.tr("@", "")
|
||||
@lvar_names = exception.respond_to?(:local_variables) ? exception.local_variables : []
|
||||
@ -0,0 +1,20 @@
|
||||
require_relative "../spell_checker"
|
||||
|
||||
module DidYouMean
|
||||
class PatternKeyNameChecker
|
||||
def initialize(no_matching_pattern_key_error)
|
||||
@key = no_matching_pattern_key_error.key
|
||||
@keys = no_matching_pattern_key_error.matchee.keys
|
||||
end
|
||||
|
||||
def corrections
|
||||
@corrections ||= exact_matches.empty? ? SpellChecker.new(dictionary: @keys).correct(@key).map(&:inspect) : exact_matches
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def exact_matches
|
||||
@exact_matches ||= @keys.select { |word| @key == word.to_s }.map(&:inspect)
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -2,13 +2,17 @@
|
||||
|
||||
require_relative "../spell_checker"
|
||||
require_relative "../tree_spell_checker"
|
||||
require "rbconfig"
|
||||
|
||||
module DidYouMean
|
||||
class RequirePathChecker
|
||||
attr_reader :path
|
||||
|
||||
INITIAL_LOAD_PATH = $LOAD_PATH.dup.freeze
|
||||
ENV_SPECIFIC_EXT = ".#{RbConfig::CONFIG["DLEXT"]}"
|
||||
Ractor.make_shareable(INITIAL_LOAD_PATH) if defined?(Ractor)
|
||||
|
||||
ENV_SPECIFIC_EXT = ".#{RbConfig::CONFIG["DLEXT"]}"
|
||||
Ractor.make_shareable(ENV_SPECIFIC_EXT) if defined?(Ractor)
|
||||
|
||||
private_constant :INITIAL_LOAD_PATH, :ENV_SPECIFIC_EXT
|
||||
|
||||
@ -0,0 +1,2 @@
|
||||
warn "The verbose formatter has been removed and now `require 'did_you_mean/verbose'` has no effect. Please " \
|
||||
"remove this call."
|
||||
@ -0,0 +1,3 @@
|
||||
module DidYouMean
|
||||
VERSION = "1.6.1".freeze
|
||||
end
|
||||
Loading…
x
Reference in New Issue
Block a user