byebug-skipper 0.3.3 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5d165edc95bf8040d55fa09985c47fb3c85b001b3c739855ec30c20c2a9e6eb6
4
- data.tar.gz: 1183e8fbae3dd8785b357ed93365eaaaf17a9de521cb52b08e1366a7abee7e94
3
+ metadata.gz: 25d8edd230ae69ad9219645ecc06700487d398b5aa024e7ee542e5f48a41c056
4
+ data.tar.gz: b4ff72166a36cab63a0b105f9c3f4ee11aa245d82717a6e19fa69587a93f11a2
5
5
  SHA512:
6
- metadata.gz: 254077cf9ff026ebf763d2b4f5a4fa061e18241f239aaa228b5a641407e5ac86bc91500547725acce8e794a78a21b7d7e67b5de83fb8cb907bfa46f5d6d5a362
7
- data.tar.gz: b5ee026c1455bbab9dea30054548c39f13b1c32258a5a2754a5576d2454d4e9761298af5bd9b5b221ac16c8ecadf7f54d6719bf8eb92824350ea4df07309bfe3
6
+ metadata.gz: 819cf45b6f634c7c78698c97aa81a5272eef2e17617560dfbe0a26fcd0aee729dcdf5ed2797e5ea50b2aa538ca87be9dd5d18a6387070b60df9a750f54370321
7
+ data.tar.gz: 107a6cf23cf5a1ec06993a1a6ff6458dd09e1813b4ed3c608aa29b749c071de08531276439166974c682c9cbe30ae7ee1091c721c58924b8cbdaea4da5ecdcce
@@ -1,8 +1,11 @@
1
+ require 'byebug'
2
+
1
3
  module Byebug::Skipper
2
4
  extend self
3
5
 
4
6
  DEFAULT_SKIP_MATCHERS = [
5
7
  %r{/ruby/[^/]+(/bundler)?/gems/}, # gems installed globally or via Bundler
8
+ %r{/ruby-[^/]+/gems/}, # RVM directory format
6
9
  %r{/ruby-[^/]+/lib/ruby/[^/]+/}, # Ruby built-in files
7
10
  ].freeze
8
11
 
@@ -20,13 +23,18 @@ module Byebug::Skipper
20
23
  end
21
24
 
22
25
  require 'delegate'
23
- require 'byebug'
24
- require 'byebug/command'
26
+ require 'tempfile'
27
+
25
28
  require 'byebug/helpers/frame'
29
+ require 'byebug/command'
30
+ require 'byebug/commands/skip'
31
+
26
32
  require_relative 'skipper/ups_command'
27
33
  require_relative 'skipper/downs_command'
28
34
  require_relative 'skipper/finishs_command'
29
35
  require_relative 'skipper/steps_command'
36
+ require_relative 'skipper/comment_line_above'
37
+ require_relative 'skipper/skip_bang_command'
30
38
 
31
39
  # Command classes need to be in the Byebug module or else they don't get picked
32
40
  # up. Cool, bruh.
@@ -35,6 +43,7 @@ require_relative 'skipper/steps_command'
35
43
  Byebug::Skipper::DownsCommand,
36
44
  Byebug::Skipper::FinishsCommand,
37
45
  Byebug::Skipper::StepsCommand,
46
+ Byebug::Skipper::SkipBangCommand,
38
47
  ].each do |command_class|
39
48
  Byebug.const_set(
40
49
  command_class.name.split('::').last,
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Byebug::Skipper
4
+ module CommentLineAbove
5
+ extend self
6
+
7
+ def call(location)
8
+ path, _, line_no = location.rpartition(':')
9
+ lines = File.readlines(path)
10
+
11
+ idx = Integer(line_no) - 2
12
+ while ignore_line?(lines[idx])
13
+ idx -= 1
14
+ return if idx < 0 # tried to go above the first line of the file, so abort
15
+ end
16
+
17
+ lines[idx] = comment_out(lines.fetch(idx))
18
+ File.write(path, lines.join)
19
+ end
20
+
21
+ private
22
+
23
+ def comment_out(line)
24
+ line.sub(/\A\s*/, '\0# ')
25
+ end
26
+
27
+ def ignore_line?(line)
28
+ line.strip.empty? || line.strip.start_with?('#')
29
+ end
30
+ end
31
+ end
@@ -2,18 +2,39 @@ require_relative '../skipper'
2
2
  require 'pry-byebug'
3
3
 
4
4
  module Byebug::Skipper::Pry
5
- COMMAND_NAMES = %w[ups downs steps finishs].freeze
6
- COMMANDS_THAT_CONTINUE = %w[steps finishs].freeze
5
+ COMMANDS = [
6
+ {
7
+ cmd: 'ups',
8
+ const_name: 'Ups',
9
+ continues?: false,
10
+ },
11
+ {
12
+ cmd: 'downs',
13
+ const_name: 'Downs',
14
+ continues?: false,
15
+ },
16
+ {
17
+ cmd: 'steps',
18
+ const_name: 'Steps',
19
+ continues?: true,
20
+ },
21
+ {
22
+ cmd: 'finishs',
23
+ const_name: 'Finishs',
24
+ continues?: true,
25
+ },
26
+ ].freeze
7
27
  end
8
28
 
9
29
  # All the Pry command classes are implemented the same
10
- Byebug::Skipper::Pry::COMMAND_NAMES.each do |command_name|
11
- command_class = Class.new(Pry::ClassCommand) do
30
+ Byebug::Skipper::Pry::COMMANDS.each do |command|
31
+ byebug_command_class = Byebug::Skipper.const_get("#{command.fetch(:const_name)}Command")
32
+ pry_command_class = Class.new(Pry::ClassCommand) do
12
33
  include ::PryByebug::Helpers::Navigation
13
34
 
14
- match command_name
35
+ match command.fetch(:cmd)
15
36
  group "Byebug Skipper"
16
- description "Same as Byebug's `#{command_name.chomp('s')}` command but skips garbage frames (e.g. from gems)"
37
+ description byebug_command_class.short_description
17
38
 
18
39
  def process
19
40
  PryByebug.check_file_context(target)
@@ -23,8 +44,8 @@ Byebug::Skipper::Pry::COMMAND_NAMES.each do |command_name|
23
44
  end
24
45
  end
25
46
 
26
- Byebug::Skipper::Pry.const_set("#{command_name.capitalize}Command", command_class)
27
- Pry::Commands.add_command(command_class)
47
+ Byebug::Skipper::Pry.const_set("#{command.fetch(:const_name)}Command", pry_command_class)
48
+ Pry::Commands.add_command(pry_command_class)
28
49
  end
29
50
 
30
51
  # This is a monkey patch for Byebug::PryProcessor in order to add extra Byebug
@@ -34,18 +55,17 @@ module Byebug::Skipper::Pry::ProcessorHacks
34
55
  def perform(action, options = {})
35
56
  # If it's not one of our commands, short circuit and use the typical
36
57
  # behaviour.
37
- return super unless Byebug::Skipper::Pry::COMMAND_NAMES.include?(action.to_s)
58
+ command = Byebug::Skipper::Pry::COMMANDS.find { _1.fetch(:cmd) == action.to_s }
59
+ return super unless command
38
60
 
39
61
  # Call the Byebug command objects directly. This seems kind of fragile to
40
62
  # me, but I don't see any better options.
41
- Byebug::Skipper.const_get("#{command_name.capitalize}Command")
42
- .new(self, command_name)
63
+ Byebug::Skipper.const_get("#{command.fetch(:const_name)}Command")
64
+ .new(self, action.to_s)
43
65
  .execute
44
66
 
45
- unless Byebug::Skipper::Pry::COMMANDS_THAT_CONTINUE.include?(command_name)
46
- # This shows the REPL again, preventing execution from continuing.
47
- resume_pry
48
- end
67
+ # This shows the REPL again, preventing execution from continuing.
68
+ resume_pry unless command.fetch(:continues?)
49
69
  end
50
70
  end
51
71
 
@@ -0,0 +1,23 @@
1
+ module Byebug::Skipper
2
+ class SkipBangCommand < Byebug::SkipCommand
3
+ def self.regexp
4
+ /^ \s* skip! \s* $/x
5
+ end
6
+
7
+ def self.short_description
8
+ "Same as `skip` but also comments out the line before the current one (where `byebug` or `binding.pry` usually is)"
9
+ end
10
+
11
+ def self.description
12
+ short_description
13
+ end
14
+
15
+ # This method gets run once when the command starts. After that, `#execute`
16
+ # gets called repeatedly from different locations, so we can't use it
17
+ # without adding random commented lines everywhere.
18
+ def initialize_attributes
19
+ CommentLineAbove.(context.location)
20
+ super
21
+ end
22
+ end
23
+ end
@@ -1,5 +1,5 @@
1
1
  module Byebug
2
2
  module Skipper
3
- VERSION = '0.3.3'
3
+ VERSION = '0.4.0'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: byebug-skipper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Dalling
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-07 00:00:00.000000000 Z
11
+ date: 2021-07-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: byebug
@@ -73,9 +73,11 @@ extensions: []
73
73
  extra_rdoc_files: []
74
74
  files:
75
75
  - lib/byebug/skipper.rb
76
+ - lib/byebug/skipper/comment_line_above.rb
76
77
  - lib/byebug/skipper/downs_command.rb
77
78
  - lib/byebug/skipper/finishs_command.rb
78
79
  - lib/byebug/skipper/pry.rb
80
+ - lib/byebug/skipper/skip_bang_command.rb
79
81
  - lib/byebug/skipper/steps_command.rb
80
82
  - lib/byebug/skipper/ups_command.rb
81
83
  - lib/byebug/skipper/version.rb