pry-byetypo 1.2.0 → 1.3.1
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 +5 -3
- data/README.md +21 -0
- data/lib/pry-byetypo/exceptions/exceptions_base.rb +2 -3
- data/lib/pry-byetypo/exceptions/no_method_error.rb +29 -0
- data/lib/pry-byetypo/exceptions_handler.rb +3 -0
- data/lib/pry-byetypo/setup/application_dictionary.rb +1 -0
- data/lib/pry-byetypo/version.rb +1 -1
- data/pry-byetypo.gemspec +0 -1
- metadata +3 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 19364c10e5d63e6ebc62aa9546e77897e7c82d833da814696f2f02acaf08c0e9
|
4
|
+
data.tar.gz: 9e2d299d10364d6bc76db71d8596b2b942ded8baa6954f90f515d3a7c73319dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f41711a85eb37c414185c405a4dffd3325b6e172113362362e1176cfe151bfd941ebc535aa0202ce296e77f1f4871a1e161cdaa79022b1cde8797dd7db9d1c3d
|
7
|
+
data.tar.gz: 21373c1b2a16ac6df0f8c5545ed93f1925295056e07618093bfbefc9ac0085398894d427b302a4bb2b3b01853b6aa4b877347c47fadb51863ff5e0f7be77594d
|
data/Gemfile.lock
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
pry-byetypo (1.
|
5
|
-
colorize (~> 1.1.0)
|
4
|
+
pry-byetypo (1.3.1)
|
6
5
|
pry (>= 0.13, < 0.15)
|
7
6
|
|
8
7
|
GEM
|
@@ -88,7 +87,6 @@ GEM
|
|
88
87
|
builder (3.2.4)
|
89
88
|
byebug (11.1.3)
|
90
89
|
coderay (1.1.3)
|
91
|
-
colorize (1.1.0)
|
92
90
|
concurrent-ruby (1.2.3)
|
93
91
|
connection_pool (2.4.1)
|
94
92
|
crass (1.0.6)
|
@@ -133,6 +131,8 @@ GEM
|
|
133
131
|
nio4r (2.7.0)
|
134
132
|
nokogiri (1.16.0-arm64-darwin)
|
135
133
|
racc (~> 1.4)
|
134
|
+
nokogiri (1.16.0-x86_64-darwin)
|
135
|
+
racc (~> 1.4)
|
136
136
|
nokogiri (1.16.0-x86_64-linux)
|
137
137
|
racc (~> 1.4)
|
138
138
|
parallel (1.23.0)
|
@@ -247,6 +247,8 @@ GEM
|
|
247
247
|
|
248
248
|
PLATFORMS
|
249
249
|
arm64-darwin-22
|
250
|
+
arm64-darwin-23
|
251
|
+
x86_64-darwin-22
|
250
252
|
x86_64-linux
|
251
253
|
|
252
254
|
DEPENDENCIES
|
data/README.md
CHANGED
@@ -87,6 +87,27 @@ I, [2024-01-31T17:11:16.344503 #3739] INFO -- : Running: result
|
|
87
87
|
=> 1
|
88
88
|
```
|
89
89
|
|
90
|
+
### NoMethodError - undefined method
|
91
|
+
|
92
|
+
This error occurs when you mispelled a method in your REPL. The gem will catch that exception and will try find the closest matches. If so, it will run the command with the (potential) corrected method.
|
93
|
+
|
94
|
+
##### Before
|
95
|
+
|
96
|
+
```ruby
|
97
|
+
[1] pry(main)> User.lasst
|
98
|
+
NoMethodError: undefined method `lasst' for User:Class
|
99
|
+
from (pry):2:in `__pry__'
|
100
|
+
```
|
101
|
+
|
102
|
+
##### After
|
103
|
+
|
104
|
+
```ruby
|
105
|
+
[1] pry(main)> User.lasst
|
106
|
+
E, [2024-01-31T17:11:16.344161 #3739] ERROR -- : undefined method `lasst' for User:Class
|
107
|
+
I, [2024-01-31T17:11:16.344503 #3739] INFO -- : Running: User.last
|
108
|
+
=> #<User id: 1, email: "yo@email.com">
|
109
|
+
```
|
110
|
+
|
90
111
|
### NameError - uninitialized constant
|
91
112
|
|
92
113
|
This error occurs when you mispelled a model in your REPL. The gem will catch that exception and will try find the closest matches. If so, it will run the command with the (potential) corrected model.
|
@@ -1,7 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "logger"
|
4
|
-
require "colorize"
|
5
4
|
require_relative "../base"
|
6
5
|
require_relative "../setup/store"
|
7
6
|
|
@@ -10,8 +9,8 @@ class ExceptionsBase < Base
|
|
10
9
|
|
11
10
|
def call
|
12
11
|
if corrected_word
|
13
|
-
logger.error(exception
|
14
|
-
logger.info("
|
12
|
+
logger.error("\e[1;31m#{exception}\e[0m")
|
13
|
+
logger.info("\e[1;32mRunning: #{corrected_cmd}\e[0m")
|
15
14
|
|
16
15
|
pry.eval(corrected_cmd)
|
17
16
|
else
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "exceptions_base"
|
4
|
+
|
5
|
+
module Exceptions
|
6
|
+
class NoMethodError < ExceptionsBase
|
7
|
+
private
|
8
|
+
|
9
|
+
def corrected_cmd
|
10
|
+
@corrected_cmd ||= last_cmd.gsub(/\b#{unknown_from_exception}\b/, corrected_word)
|
11
|
+
end
|
12
|
+
|
13
|
+
def unknown_from_exception
|
14
|
+
exception.to_s.match(exception_regexp)[1]
|
15
|
+
end
|
16
|
+
|
17
|
+
def dictionary
|
18
|
+
eval(klass).methods.map(&:to_s) # rubocop:disable Security/Eval
|
19
|
+
end
|
20
|
+
|
21
|
+
def exception_regexp
|
22
|
+
/`([^']+)' for/
|
23
|
+
end
|
24
|
+
|
25
|
+
def klass
|
26
|
+
exception.to_s.match(/for\s+(.*?):\w*$/)[1]
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -4,6 +4,7 @@ require_relative "base"
|
|
4
4
|
require_relative "exceptions/active_record/statement_invalid"
|
5
5
|
require_relative "exceptions/active_record/configuration_error"
|
6
6
|
require_relative "exceptions/name_error/handler"
|
7
|
+
require_relative "exceptions/no_method_error"
|
7
8
|
require_relative "constants/errors"
|
8
9
|
|
9
10
|
class ExceptionsHandler < Base
|
@@ -17,6 +18,8 @@ class ExceptionsHandler < Base
|
|
17
18
|
|
18
19
|
def call
|
19
20
|
case exception
|
21
|
+
in NoMethodError
|
22
|
+
Exceptions::NoMethodError.call(output, exception, pry)
|
20
23
|
in NameError
|
21
24
|
# NameError is a Superclass for all undefined statement.
|
22
25
|
Exceptions::NameError::Handler.call(output, exception, pry)
|
data/lib/pry-byetypo/version.rb
CHANGED
data/pry-byetypo.gemspec
CHANGED
@@ -29,6 +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 "colorize", "~> 1.1.0"
|
33
32
|
gem.add_runtime_dependency "pry", ">= 0.13", "< 0.15"
|
34
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.
|
4
|
+
version: 1.3.1
|
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: 2024-02
|
11
|
+
date: 2024-03-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -24,20 +24,6 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '7.0'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: colorize
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: 1.1.0
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - "~>"
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: 1.1.0
|
41
27
|
- !ruby/object:Gem::Dependency
|
42
28
|
name: pry
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -85,6 +71,7 @@ files:
|
|
85
71
|
- lib/pry-byetypo/exceptions/exceptions_base.rb
|
86
72
|
- lib/pry-byetypo/exceptions/name_error/handler.rb
|
87
73
|
- lib/pry-byetypo/exceptions/name_error/undefined_variable.rb
|
74
|
+
- lib/pry-byetypo/exceptions/no_method_error.rb
|
88
75
|
- lib/pry-byetypo/exceptions_handler.rb
|
89
76
|
- lib/pry-byetypo/session/clear_history.rb
|
90
77
|
- lib/pry-byetypo/session/populate_history.rb
|