pry-byetypo 1.3.4 → 1.3.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +3 -3
- data/lib/pry-byetypo/exceptions/active_record/base.rb +1 -1
- data/lib/pry-byetypo/exceptions/active_record/uninitialized_constant.rb +2 -1
- data/lib/pry-byetypo/exceptions/exceptions_base.rb +11 -1
- data/lib/pry-byetypo/exceptions/no_method_error.rb +31 -7
- data/lib/pry-byetypo/setup/dictionary/active_record.rb +8 -4
- data/lib/pry-byetypo/version.rb +1 -1
- data/pry-byetypo.gemspec +1 -1
- metadata +5 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a33e074d9f5da4f065da3f5cdbf37807b1de2a0565d81a3bf89f0fd751286ee5
|
4
|
+
data.tar.gz: 59b098fd8d154d4315c931a9869b0feedcbed19e022ecb71f828b61913759d13
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 158849f7db42283374d60ed2cc3fee8c48443101870cbb03ba5e032ee5a0a467c07b0fa584afba5428cecc98cd4528113d66447a760c77ee539fe136e6f008ee
|
7
|
+
data.tar.gz: 5cf13d244cef3a3f8538ad21817bd179a67fbd2fb6170ff5c85e80f959f179c4a0ffa8eb38408006b862f727b381811d622a010cb7daed799cca4939c5d85a8f
|
data/Gemfile.lock
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
pry-byetypo (1.3.
|
5
|
-
pry (
|
4
|
+
pry-byetypo (1.3.6)
|
5
|
+
pry (~> 0.15)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
@@ -139,7 +139,7 @@ GEM
|
|
139
139
|
parser (3.2.2.4)
|
140
140
|
ast (~> 2.4.1)
|
141
141
|
racc
|
142
|
-
pry (0.
|
142
|
+
pry (0.15.2)
|
143
143
|
coderay (~> 1.1)
|
144
144
|
method_source (~> 1.0)
|
145
145
|
psych (5.1.2)
|
@@ -8,7 +8,7 @@ module Exceptions
|
|
8
8
|
private
|
9
9
|
|
10
10
|
def corrected_cmd
|
11
|
-
@corrected_cmd ||= last_cmd.gsub(/\b#{unknown_from_exception}\b/, corrected_word)
|
11
|
+
@corrected_cmd ||= last_cmd.gsub(/\b#{unknown_from_exception}\b/, corrected_word.to_s)
|
12
12
|
end
|
13
13
|
|
14
14
|
def unknown_from_exception
|
@@ -29,6 +29,8 @@ class ExceptionsBase < Base
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def can_correct?
|
32
|
+
return true if did_you_mean_output
|
33
|
+
|
32
34
|
error_from_typo? && dictionary && corrected_word
|
33
35
|
end
|
34
36
|
|
@@ -37,7 +39,15 @@ class ExceptionsBase < Base
|
|
37
39
|
end
|
38
40
|
|
39
41
|
def corrected_word
|
40
|
-
@corrected_word ||=
|
42
|
+
@corrected_word ||= did_you_mean_output ||
|
43
|
+
spell_checker.correct(unknown_from_exception).first
|
44
|
+
end
|
45
|
+
|
46
|
+
def did_you_mean_output
|
47
|
+
match_data = exception.message.match(/Did you mean\?\s+(\w+)/)
|
48
|
+
return unless match_data
|
49
|
+
|
50
|
+
match_data[1]
|
41
51
|
end
|
42
52
|
|
43
53
|
def spell_checker
|
@@ -15,21 +15,45 @@ module Exceptions
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def dictionary
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
@dictionary ||= begin
|
19
|
+
klass_eval = eval(infer_klass) # rubocop:disable Security/Eval
|
20
|
+
klass_methods = klass_eval.methods
|
21
|
+
# Conditions below exist because built_in class does not have access to `instance_methods` or `column_names`. eg: []
|
22
|
+
instance_methods = klass_eval.respond_to?(:instance_methods) ? klass_eval.instance_methods(false) : []
|
23
|
+
column_names = klass_eval.respond_to?(:column_names) ? klass_eval.column_names : []
|
21
24
|
|
22
|
-
|
23
|
-
|
25
|
+
[instance_methods, klass_methods, model_associations, column_names, active_records_methods].flatten.map(&:to_s)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def model_associations
|
30
|
+
store.transaction { |s| [s["associations"]] }
|
31
|
+
end
|
32
|
+
|
33
|
+
def active_records_methods
|
34
|
+
store.transaction { |s| [s["ar_methods"]] }
|
24
35
|
end
|
25
36
|
|
26
37
|
def exception_regexp
|
27
38
|
/`([^']+)' for/
|
28
39
|
end
|
29
40
|
|
41
|
+
def klass_regexp
|
42
|
+
return /for an instance of (\w+)/ if instance_exception?
|
43
|
+
return /for class (\w+)/ if exception.to_s.include?("class")
|
44
|
+
|
45
|
+
/for #<(\w+)/
|
46
|
+
end
|
47
|
+
|
30
48
|
def klass
|
31
|
-
|
32
|
-
|
49
|
+
@klass ||= begin
|
50
|
+
exception_without_class_module = exception.to_s.match(klass_regexp)
|
51
|
+
exception_without_class_module[1]
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def instance_exception?
|
56
|
+
exception.to_s.include?("for an instance of")
|
33
57
|
end
|
34
58
|
|
35
59
|
# [].methods and Array.methods have a different output.
|
@@ -5,6 +5,7 @@ require_relative "../checks/database_pool"
|
|
5
5
|
require_relative "../store"
|
6
6
|
|
7
7
|
require "pstore"
|
8
|
+
require "zeitwerk"
|
8
9
|
|
9
10
|
module Setup
|
10
11
|
module Dictionary
|
@@ -25,6 +26,7 @@ module Setup
|
|
25
26
|
|
26
27
|
store["active_record_models"] = populate_active_record_models_dictionary
|
27
28
|
store["associations"] = populate_associations
|
29
|
+
store["ar_methods"] = ::ActiveRecord::Base.methods
|
28
30
|
store["synced_at"] = Time.now
|
29
31
|
end
|
30
32
|
end
|
@@ -36,13 +38,15 @@ module Setup
|
|
36
38
|
|
37
39
|
def populate_active_record_models_dictionary
|
38
40
|
Zeitwerk::Loader.eager_load_all
|
39
|
-
|
41
|
+
models.map { |model| format_active_record_model(model) }.flatten
|
40
42
|
end
|
41
43
|
|
42
44
|
def populate_associations
|
43
|
-
|
44
|
-
|
45
|
-
|
45
|
+
models.map { |model| model.reflect_on_all_associations.map(&:name) }.flatten.uniq
|
46
|
+
end
|
47
|
+
|
48
|
+
def models
|
49
|
+
@models ||= ::ActiveRecord::Base.descendants
|
46
50
|
end
|
47
51
|
|
48
52
|
# This method takes an ActiveRecord model as an argument and formats its name and module information.
|
data/lib/pry-byetypo/version.rb
CHANGED
data/pry-byetypo.gemspec
CHANGED
@@ -29,5 +29,5 @@ Gem::Specification.new do |gem|
|
|
29
29
|
gem.executables = gem.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
30
30
|
gem.require_paths = ["lib"]
|
31
31
|
gem.add_development_dependency "rails", "~> 7.0"
|
32
|
-
gem.add_runtime_dependency "pry", "
|
32
|
+
gem.add_runtime_dependency "pry", "~> 0.15"
|
33
33
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pry-byetypo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Clément Morisset
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-02-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -28,20 +28,14 @@ dependencies:
|
|
28
28
|
name: pry
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0.13'
|
34
|
-
- - "<"
|
31
|
+
- - "~>"
|
35
32
|
- !ruby/object:Gem::Version
|
36
33
|
version: '0.15'
|
37
34
|
type: :runtime
|
38
35
|
prerelease: false
|
39
36
|
version_requirements: !ruby/object:Gem::Requirement
|
40
37
|
requirements:
|
41
|
-
- - "
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
version: '0.13'
|
44
|
-
- - "<"
|
38
|
+
- - "~>"
|
45
39
|
- !ruby/object:Gem::Version
|
46
40
|
version: '0.15'
|
47
41
|
description: This Pry plugin captures exceptions that could be due to typos and deduces
|
@@ -108,7 +102,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
108
102
|
- !ruby/object:Gem::Version
|
109
103
|
version: '0'
|
110
104
|
requirements: []
|
111
|
-
rubygems_version: 3.4.
|
105
|
+
rubygems_version: 3.4.1
|
112
106
|
signing_key:
|
113
107
|
specification_version: 4
|
114
108
|
summary: Autocorrects typos in your Pry console
|