pry-byetypo 1.3.2 → 1.3.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b0a93b11d72346335618ba4ba38487e30b7b83c3a8460b11ad08987b903a5349
4
- data.tar.gz: 3014b3bfda0207d5fecb14b0ba1dd421404e383b8ddcc3077bd5912f59063f60
3
+ metadata.gz: ed71926ad9667df2634d402ea3a0e38d90ceff651a9f5b2edb0347bebe838d07
4
+ data.tar.gz: 82307bfd3c93fac14f66cb1fc128f3a12919814ca4ef428deb90baf0a69540e8
5
5
  SHA512:
6
- metadata.gz: 7b5c2b5b46aad5f54b6b7a84738eeba57f51e4e799150e9c197cb4ebb6e413ca5498635555b777b58dccad44f88195d968f0cc3d87400b2581c687cd1ccc4fc6
7
- data.tar.gz: e7cbd3b2c198c11e4cdc91eb5ce057aea760e83292e116ba0bb6a50c737b84a9f811503ce4f84ee210f698008d661d7f372fb5b9302e79c02513a0e1264d8ecf
6
+ metadata.gz: 73f5da8a471e861ac2bb7489ae22ba43c7d1c67d757404cb1b7b422298894d6c797fb269b982c7661b1e4f3e1e2495b4f0ef2e678593d425bfdea58ea3f52573
7
+ data.tar.gz: 43233f889ac57d2ef94c67db75821656a76574be8d9e39b192157fae8aa993275df2ebdd69b40f275369a65f980705fa9ae0a8e917132cb91e5dfb3318a7c9ab
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pry-byetypo (1.3.2)
4
+ pry-byetypo (1.3.4)
5
5
  pry (>= 0.13, < 0.15)
6
6
 
7
7
  GEM
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 ORM-agnostic; to fully benefit from it, ActiveRecord is required.
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
- ### NameError - uninitialized constant
112
+ ### UndefinedColumn
112
113
 
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.
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)> Usert.last
119
- NameError: uninitialized constant Usert
120
- from (pry):2:in `__pry__'
121
- [3] pry(main)>
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)> Usert.last
128
- I, [2024-01-13T20:00:16.280710 #694] ERROR -- : uninitialized constant Usert
129
- I, [2024-01-13T20:00:16.281237 #694] INFO -- : Running: User.last
130
- => #<User id: 1, email: "yo@email.com">
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
- UNINITIALIZED_CONSTANT = "uninitialized constant".freeze
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
@@ -15,7 +15,12 @@ module Exceptions
15
15
  end
16
16
 
17
17
  def dictionary
18
- eval(infer_klass).methods.map(&:to_s) # rubocop:disable Security/Eval
18
+ klass_methods = eval(infer_klass).methods # rubocop:disable Security/Eval
19
+ # Early return because built_in class does not have access to `instance_methods`.
20
+ return klass_methods.map(&:to_s) if built_in_klass
21
+
22
+ instance_methods = eval(infer_klass).instance_methods(false) # rubocop:disable Security/Eval
23
+ instance_methods.push(klass_methods).flatten.map(&:to_s)
19
24
  end
20
25
 
21
26
  def exception_regexp
@@ -35,5 +40,9 @@ module Exceptions
35
40
 
36
41
  "[]"
37
42
  end
43
+
44
+ def built_in_klass
45
+ infer_klass == "[]"
46
+ end
38
47
  end
39
48
  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
- # ActiveRecord::StatementInvalid is a Superclass for all database execution errors.
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
@@ -65,7 +65,8 @@ module Setup
65
65
  end
66
66
 
67
67
  def database_config
68
- YAML.safe_load(File.read(database_config_path), aliases: true)
68
+ erb_content = ERB.new(File.read(database_config_path)).result
69
+ YAML.safe_load(erb_content, aliases: true)
69
70
  end
70
71
 
71
72
  def logger
@@ -2,6 +2,6 @@
2
2
 
3
3
  class Pry
4
4
  module Byetypo
5
- VERSION = "1.3.2"
5
+ VERSION = "1.3.4"
6
6
  end
7
7
  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.2
4
+ version: 1.3.4
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-03-16 00:00:00.000000000 Z
11
+ date: 2024-09-06 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.4.19
111
+ rubygems_version: 3.4.22
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