pry-byetypo 1.3.0 → 1.3.2

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: da8cec30c93c393374f141f18ce63052a9019f7cdeb07ef812b82a66cb050a34
4
- data.tar.gz: 7310aa51a6dbfb284b970049317e11036fd2dcc2449f33565e879c8604e4ca5d
3
+ metadata.gz: b0a93b11d72346335618ba4ba38487e30b7b83c3a8460b11ad08987b903a5349
4
+ data.tar.gz: 3014b3bfda0207d5fecb14b0ba1dd421404e383b8ddcc3077bd5912f59063f60
5
5
  SHA512:
6
- metadata.gz: d7c23c25abd958cd72a5298c9b4c1c02a4cae85e2147a7d0051ee4e58392c298a7a5a852fa89ba43fcb260d7843210529cbb7dcee3e82290afd425faec4deabb
7
- data.tar.gz: cb4b3db82a3f9414eebd451d88c3383044207799e4cedeaaf47b621d62f3f72569b3e1a39e9afc26694ba1e01fab50dd4680f2768d4d4a2831612de60de7733b
6
+ metadata.gz: 7b5c2b5b46aad5f54b6b7a84738eeba57f51e4e799150e9c197cb4ebb6e413ca5498635555b777b58dccad44f88195d968f0cc3d87400b2581c687cd1ccc4fc6
7
+ data.tar.gz: e7cbd3b2c198c11e4cdc91eb5ce057aea760e83292e116ba0bb6a50c737b84a9f811503ce4f84ee210f698008d661d7f372fb5b9302e79c02513a0e1264d8ecf
data/Gemfile.lock CHANGED
@@ -1,8 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pry-byetypo (1.3.0)
5
- colorize (~> 1.1.0)
4
+ pry-byetypo (1.3.2)
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)
@@ -248,6 +248,7 @@ GEM
248
248
  PLATFORMS
249
249
  arm64-darwin-22
250
250
  arm64-darwin-23
251
+ x86_64-darwin-22
251
252
  x86_64-linux
252
253
 
253
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
 
@@ -9,9 +8,9 @@ class ExceptionsBase < Base
9
8
  include Setup::Store
10
9
 
11
10
  def call
12
- if corrected_word
13
- logger.error(exception.to_s.colorize(color: :light_red, mode: :bold))
14
- logger.info("Running: #{corrected_cmd}".colorize(color: :green, mode: :bold))
11
+ if can_correct?
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
@@ -29,6 +28,14 @@ class ExceptionsBase < Base
29
28
  @pry = pry
30
29
  end
31
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
+
32
39
  def corrected_word
33
40
  @corrected_word ||= spell_checker.correct(unknown_from_exception).first
34
41
  end
@@ -15,7 +15,7 @@ module Exceptions
15
15
  end
16
16
 
17
17
  def dictionary
18
- eval(klass).methods.map(&:to_s) # rubocop:disable Security/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.match(/for\s+(.*?):\w*$/)[1]
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
@@ -15,6 +15,7 @@ module Setup
15
15
 
16
16
  def call
17
17
  Setup::Dictionary::ActiveRecord.initialize! if defined?(ActiveRecord)
18
+ ensure
18
19
  populate_store
19
20
  end
20
21
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  class Pry
4
4
  module Byetypo
5
- VERSION = "1.3.0"
5
+ VERSION = "1.3.2"
6
6
  end
7
7
  end
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.3.0
4
+ version: 1.3.2
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-29 00:00:00.000000000 Z
11
+ date: 2024-03-16 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
@@ -120,7 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
120
106
  - !ruby/object:Gem::Version
121
107
  version: '0'
122
108
  requirements: []
123
- rubygems_version: 3.4.22
109
+ rubygems_version: 3.4.19
124
110
  signing_key:
125
111
  specification_version: 4
126
112
  summary: Autocorrects typos in your Pry console