byebug-skipper 0.3.3 → 0.4.0
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/lib/byebug/skipper.rb +11 -2
- data/lib/byebug/skipper/comment_line_above.rb +31 -0
- data/lib/byebug/skipper/pry.rb +35 -15
- data/lib/byebug/skipper/skip_bang_command.rb +23 -0
- data/lib/byebug/skipper/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 25d8edd230ae69ad9219645ecc06700487d398b5aa024e7ee542e5f48a41c056
|
4
|
+
data.tar.gz: b4ff72166a36cab63a0b105f9c3f4ee11aa245d82717a6e19fa69587a93f11a2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 819cf45b6f634c7c78698c97aa81a5272eef2e17617560dfbe0a26fcd0aee729dcdf5ed2797e5ea50b2aa538ca87be9dd5d18a6387070b60df9a750f54370321
|
7
|
+
data.tar.gz: 107a6cf23cf5a1ec06993a1a6ff6458dd09e1813b4ed3c608aa29b749c071de08531276439166974c682c9cbe30ae7ee1091c721c58924b8cbdaea4da5ecdcce
|
data/lib/byebug/skipper.rb
CHANGED
@@ -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 '
|
24
|
-
|
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
|
data/lib/byebug/skipper/pry.rb
CHANGED
@@ -2,18 +2,39 @@ require_relative '../skipper'
|
|
2
2
|
require 'pry-byebug'
|
3
3
|
|
4
4
|
module Byebug::Skipper::Pry
|
5
|
-
|
6
|
-
|
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::
|
11
|
-
|
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
|
35
|
+
match command.fetch(:cmd)
|
15
36
|
group "Byebug Skipper"
|
16
|
-
description
|
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("#{
|
27
|
-
Pry::Commands.add_command(
|
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
|
-
|
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("#{
|
42
|
-
.new(self,
|
63
|
+
Byebug::Skipper.const_get("#{command.fetch(:const_name)}Command")
|
64
|
+
.new(self, action.to_s)
|
43
65
|
.execute
|
44
66
|
|
45
|
-
|
46
|
-
|
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
|
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.
|
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-
|
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
|