pry-byetypo 1.3.1 → 1.3.3
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 +1 -1
- data/README.md +39 -32
- data/lib/pry-byetypo/constants/errors.rb +3 -2
- data/lib/pry-byetypo/exceptions/active_record/statement_invalid/handler.rb +36 -0
- data/lib/pry-byetypo/exceptions/active_record/statement_invalid/undefined_column.rb +38 -0
- data/lib/pry-byetypo/exceptions/active_record/statement_invalid/undefined_table.rb +17 -0
- data/lib/pry-byetypo/exceptions/exceptions_base.rb +9 -1
- data/lib/pry-byetypo/exceptions/no_method_error.rb +12 -2
- data/lib/pry-byetypo/exceptions_handler.rb +2 -5
- data/lib/pry-byetypo/version.rb +1 -1
- metadata +6 -4
- data/lib/pry-byetypo/exceptions/active_record/statement_invalid.rb +0 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6625ca5eccb6c5953192b436b7c39cb907cd594aa1727c05e6bdc3a36a61ef37
|
4
|
+
data.tar.gz: 4e8ffb997e22b265fb238c1c7feac89668d66ee60b74a87ced1f7ba33fc6ba64
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1bf268550d2b31a241534c795d55ba431b841cedf546686fe0c57c695a0ef5790329e33fe60f0569290cfc26458997e9bfc30bfa7eff4d8ff41f818b66ead9cb
|
7
|
+
data.tar.gz: 0bb3d4377ea47c2d7beb39d15011e77000cd007fcf6e1905a9c62ceff415d31456d9ea88a8b2d7429019107bc32ff6b9e2354ade9c32b30cecc77385c74712d2
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -4,29 +4,8 @@ Autocorrects typos in your Pry console.
|
|
4
4
|
|
5
5
|
This small Pry plugin captures exceptions that may arise from typos and deduces the correct command based on your database information and session history.
|
6
6
|
|
7
|
-
#### Before
|
8
|
-
|
9
|
-
```ruby
|
10
|
-
[1] pry(main)> result = 1
|
11
|
-
=> 1
|
12
|
-
[2] pry(main)> resilt
|
13
|
-
NameError: undefined local variable or method `resilt' for main:Object
|
14
|
-
from (pry):2:in `__pry__'
|
15
|
-
```
|
16
|
-
|
17
|
-
#### After
|
18
|
-
|
19
|
-
```ruby
|
20
|
-
[1] pry(main)> result = 1
|
21
|
-
=> 1
|
22
|
-
[2] pry(main)> resilt
|
23
|
-
E, [2024-01-31T17:11:16.344161 #3739] ERROR -- : undefined local variable or method `resilt' for main:Object
|
24
|
-
I, [2024-01-31T17:11:16.344503 #3739] INFO -- : Running: result
|
25
|
-
=> 1
|
26
|
-
```
|
27
|
-
|
28
7
|
> [!NOTE]
|
29
|
-
> Currently, this plugin is not truly
|
8
|
+
> Currently, this plugin is not truly agnostic; to fully benefit from it, ActiveRecord with PostgreSQL is required.
|
30
9
|
|
31
10
|
## Installation
|
32
11
|
|
@@ -87,6 +66,28 @@ I, [2024-01-31T17:11:16.344503 #3739] INFO -- : Running: result
|
|
87
66
|
=> 1
|
88
67
|
```
|
89
68
|
|
69
|
+
### NameError - uninitialized constant
|
70
|
+
|
71
|
+
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.
|
72
|
+
|
73
|
+
##### Before
|
74
|
+
|
75
|
+
```ruby
|
76
|
+
[2] pry(main)> Usert.last
|
77
|
+
NameError: uninitialized constant Usert
|
78
|
+
from (pry):2:in `__pry__'
|
79
|
+
[3] pry(main)>
|
80
|
+
```
|
81
|
+
|
82
|
+
##### After
|
83
|
+
|
84
|
+
```ruby
|
85
|
+
[1] pry(main)> Usert.last
|
86
|
+
I, [2024-01-13T20:00:16.280710 #694] ERROR -- : uninitialized constant Usert
|
87
|
+
I, [2024-01-13T20:00:16.281237 #694] INFO -- : Running: User.last
|
88
|
+
=> #<User id: 1, email: "yo@email.com">
|
89
|
+
```
|
90
|
+
|
90
91
|
### NoMethodError - undefined method
|
91
92
|
|
92
93
|
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.
|
@@ -108,26 +109,32 @@ I, [2024-01-31T17:11:16.344503 #3739] INFO -- : Running: User.last
|
|
108
109
|
=> #<User id: 1, email: "yo@email.com">
|
109
110
|
```
|
110
111
|
|
111
|
-
###
|
112
|
+
### UndefinedColumn
|
112
113
|
|
113
|
-
This error occurs when you mispelled a
|
114
|
+
This error occurs when you mispelled a column 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 column.
|
114
115
|
|
115
116
|
##### Before
|
116
117
|
|
117
118
|
```ruby
|
118
|
-
[2] pry(main)>
|
119
|
-
|
120
|
-
|
121
|
-
|
119
|
+
[2] pry(main)> User.find_by(emil: "yo@email.com")
|
120
|
+
E, [2024-03-31T00:14:12.907708 #11761] ERROR -- : PG::UndefinedColumn: ERROR: column users.emil does not exist
|
121
|
+
LINE 1: ...OM "users" WHERE "users"."deleted_at" IS NULL AND "users"."e...
|
122
|
+
^
|
123
|
+
HINT: Perhaps you meant to reference the column "users.email".
|
122
124
|
```
|
123
125
|
|
124
126
|
##### After
|
125
127
|
|
126
128
|
```ruby
|
127
|
-
[1] pry(main)>
|
128
|
-
|
129
|
-
|
130
|
-
|
129
|
+
[1] pry(main)> User.find_by(emil: "yo@email.com")
|
130
|
+
E, [2024-03-31T00:14:12.907708 #11761] ERROR -- : PG::UndefinedColumn: ERROR: column users.emil does not exist
|
131
|
+
LINE 1: ...OM "users" WHERE "users"."deleted_at" IS NULL AND "users"."e...
|
132
|
+
^
|
133
|
+
HINT: Perhaps you meant to reference the column "users.email".
|
134
|
+
|
135
|
+
I, [2024-03-31T00:14:12.908257 #11761] INFO -- : Running: User.find_by(email: "yo@email.com")
|
136
|
+
2024-03-31 00:14:12.915906 D [11761:9180 log_subscriber.rb:130] ActiveRecord::Base -- User Load (1.0ms) SELECT "users".* FROM "users" WHERE "users"."deleted_at" IS NULL AND "users"."email" = $1 LIMIT $2 [["email", "yo@email.com"], ["LIMIT", 1]]
|
137
|
+
=> #<User id: 1, email: "yo@email.com", ...>
|
131
138
|
```
|
132
139
|
|
133
140
|
### ActiveRecord::ConfigurationError
|
@@ -1,7 +1,8 @@
|
|
1
1
|
module Constants
|
2
2
|
module Errors
|
3
|
-
|
4
|
-
UNDEFINED_VARIABLE = "undefined local variable".freeze
|
3
|
+
UNDEFINED_COLUMN = "UndefinedColumn".freeze
|
5
4
|
UNDEFINED_TABLE = "UndefinedTable".freeze
|
5
|
+
UNDEFINED_VARIABLE = "undefined local variable".freeze
|
6
|
+
UNINITIALIZED_CONSTANT = "uninitialized constant".freeze
|
6
7
|
end
|
7
8
|
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "../../exceptions_base"
|
4
|
+
require_relative "../../../constants/errors"
|
5
|
+
require_relative "undefined_table"
|
6
|
+
require_relative "undefined_column"
|
7
|
+
|
8
|
+
module Exceptions
|
9
|
+
module ActiveRecord
|
10
|
+
module StatementInvalid
|
11
|
+
class Handler < ExceptionsBase
|
12
|
+
attr_reader :exception, :output, :pry
|
13
|
+
|
14
|
+
def initialize(output, exception, pry)
|
15
|
+
@output = output
|
16
|
+
@exception = exception
|
17
|
+
@pry = pry
|
18
|
+
end
|
19
|
+
|
20
|
+
# FIXME: https://github.com/rubocop/rubocop-performance/issues/438
|
21
|
+
# rubocop:disable Performance/ConstantRegexp
|
22
|
+
def call
|
23
|
+
case exception.message
|
24
|
+
in /#{Constants::Errors::UNDEFINED_TABLE}/
|
25
|
+
UndefinedTable.call(output, exception, pry)
|
26
|
+
in /#{Constants::Errors::UNDEFINED_COLUMN}/
|
27
|
+
UndefinedColumn.call(output, exception, pry)
|
28
|
+
else
|
29
|
+
Pry::ExceptionHandler.handle_exception(output, exception, pry)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
# rubocop:enable Performance/ConstantRegexp
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "../base"
|
4
|
+
|
5
|
+
module Exceptions
|
6
|
+
module ActiveRecord
|
7
|
+
module StatementInvalid
|
8
|
+
class UndefinedColumn < Base
|
9
|
+
private
|
10
|
+
|
11
|
+
def can_correct?
|
12
|
+
corrected_word.present?
|
13
|
+
end
|
14
|
+
|
15
|
+
def unknown_from_exception
|
16
|
+
exception.to_s.match(exception_regexp)[1]
|
17
|
+
end
|
18
|
+
|
19
|
+
def corrected_word
|
20
|
+
match = exception.to_s.match(hint_regexp)
|
21
|
+
return if match.nil?
|
22
|
+
|
23
|
+
match[1].split(".").last
|
24
|
+
end
|
25
|
+
|
26
|
+
# The not found column name
|
27
|
+
def exception_regexp
|
28
|
+
/column \w+\.(\w+)\s/
|
29
|
+
end
|
30
|
+
|
31
|
+
# The hint generated by PG
|
32
|
+
def hint_regexp
|
33
|
+
/"(\w+\.\w+)"/
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "../base"
|
4
|
+
|
5
|
+
module Exceptions
|
6
|
+
module ActiveRecord
|
7
|
+
module StatementInvalid
|
8
|
+
class UndefinedTable < Base
|
9
|
+
private
|
10
|
+
|
11
|
+
def exception_regexp
|
12
|
+
/PG::UndefinedTable: ERROR: missing FROM-clause entry for table "(.*?)"\nLINE/
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -8,7 +8,7 @@ class ExceptionsBase < Base
|
|
8
8
|
include Setup::Store
|
9
9
|
|
10
10
|
def call
|
11
|
-
if
|
11
|
+
if can_correct?
|
12
12
|
logger.error("\e[1;31m#{exception}\e[0m")
|
13
13
|
logger.info("\e[1;32mRunning: #{corrected_cmd}\e[0m")
|
14
14
|
|
@@ -28,6 +28,14 @@ class ExceptionsBase < Base
|
|
28
28
|
@pry = pry
|
29
29
|
end
|
30
30
|
|
31
|
+
def can_correct?
|
32
|
+
error_from_typo? && dictionary && corrected_word
|
33
|
+
end
|
34
|
+
|
35
|
+
def error_from_typo?
|
36
|
+
last_cmd.include?(unknown_from_exception)
|
37
|
+
end
|
38
|
+
|
31
39
|
def corrected_word
|
32
40
|
@corrected_word ||= spell_checker.correct(unknown_from_exception).first
|
33
41
|
end
|
@@ -15,7 +15,7 @@ module Exceptions
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def dictionary
|
18
|
-
eval(
|
18
|
+
eval(infer_klass).methods.map(&:to_s) # rubocop:disable Security/Eval
|
19
19
|
end
|
20
20
|
|
21
21
|
def exception_regexp
|
@@ -23,7 +23,17 @@ module Exceptions
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def klass
|
26
|
-
exception.to_s.
|
26
|
+
exception_without_class_module = exception.to_s.gsub(":Class", "")
|
27
|
+
exception_without_class_module.split.last
|
28
|
+
end
|
29
|
+
|
30
|
+
# [].methods and Array.methods have a different output.
|
31
|
+
# Array class is a part of the Ruby core library while `[]` is an instance of the Array class.
|
32
|
+
# When calling [].methods, we inspect the methods available to instances of the Array class, including those inherited from its class and ancestors.
|
33
|
+
def infer_klass
|
34
|
+
return klass if klass != "Array"
|
35
|
+
|
36
|
+
"[]"
|
27
37
|
end
|
28
38
|
end
|
29
39
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative "base"
|
4
|
-
require_relative "exceptions/active_record/statement_invalid"
|
4
|
+
require_relative "exceptions/active_record/statement_invalid/handler"
|
5
5
|
require_relative "exceptions/active_record/configuration_error"
|
6
6
|
require_relative "exceptions/name_error/handler"
|
7
7
|
require_relative "exceptions/no_method_error"
|
@@ -24,10 +24,7 @@ class ExceptionsHandler < Base
|
|
24
24
|
# NameError is a Superclass for all undefined statement.
|
25
25
|
Exceptions::NameError::Handler.call(output, exception, pry)
|
26
26
|
in ActiveRecord::StatementInvalid
|
27
|
-
|
28
|
-
# We only need to one including an `UndefinedTable` error.
|
29
|
-
return pry_exception_handler unless exception.message.include?(Constants::Errors::UNDEFINED_TABLE)
|
30
|
-
Exceptions::ActiveRecord::StatementInvalid.call(output, exception, pry)
|
27
|
+
Exceptions::ActiveRecord::StatementInvalid::Handler.call(output, exception, pry)
|
31
28
|
in ActiveRecord::ConfigurationError
|
32
29
|
Exceptions::ActiveRecord::ConfigurationError.call(output, exception, pry)
|
33
30
|
else
|
data/lib/pry-byetypo/version.rb
CHANGED
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.3
|
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-
|
11
|
+
date: 2024-04-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -66,7 +66,9 @@ files:
|
|
66
66
|
- lib/pry-byetypo/constants/errors.rb
|
67
67
|
- lib/pry-byetypo/exceptions/active_record/base.rb
|
68
68
|
- lib/pry-byetypo/exceptions/active_record/configuration_error.rb
|
69
|
-
- lib/pry-byetypo/exceptions/active_record/statement_invalid.rb
|
69
|
+
- lib/pry-byetypo/exceptions/active_record/statement_invalid/handler.rb
|
70
|
+
- lib/pry-byetypo/exceptions/active_record/statement_invalid/undefined_column.rb
|
71
|
+
- lib/pry-byetypo/exceptions/active_record/statement_invalid/undefined_table.rb
|
70
72
|
- lib/pry-byetypo/exceptions/active_record/uninitialized_constant.rb
|
71
73
|
- lib/pry-byetypo/exceptions/exceptions_base.rb
|
72
74
|
- lib/pry-byetypo/exceptions/name_error/handler.rb
|
@@ -106,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
106
108
|
- !ruby/object:Gem::Version
|
107
109
|
version: '0'
|
108
110
|
requirements: []
|
109
|
-
rubygems_version: 3.
|
111
|
+
rubygems_version: 3.5.3
|
110
112
|
signing_key:
|
111
113
|
specification_version: 4
|
112
114
|
summary: Autocorrects typos in your Pry console
|
@@ -1,15 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative "base"
|
4
|
-
|
5
|
-
module Exceptions
|
6
|
-
module ActiveRecord
|
7
|
-
class StatementInvalid < Base
|
8
|
-
private
|
9
|
-
|
10
|
-
def exception_regexp
|
11
|
-
/PG::UndefinedTable: ERROR: missing FROM-clause entry for table "(.*?)"\nLINE/
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|