pry-toggle 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/pry-tgl +7 -0
- data/bin/pry-toggle +1 -1
- data/lib/pry_toggle/exec.rb +16 -3
- data/lib/pry_toggle/service.rb +14 -9
- data/lib/pry_toggle/version.rb +1 -1
- data/test/test_pry_toggle.rb +38 -5
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c50c1a062d4f71f37e5e651d8c7b38326d6acc17
|
4
|
+
data.tar.gz: 14c7b2a564de915689871920f3df37e2992badf9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 001f54a7b6f663808f2914882811ae84fc5a5354dc7862107345f01c6e06862aaacdffd783c7f25259ac204281c4da1fd7e4aebdc18c625f218574e3159c555a
|
7
|
+
data.tar.gz: 51767b9d3c296e9882fe9a92d394263834fa559f4e6ac5d0a5f08194fd8a4753e4280fbcca9cd434043d3a6cd49b604673e644f9ea1513a5eb8a8a15db475d12
|
data/bin/pry-tgl
ADDED
data/bin/pry-toggle
CHANGED
data/lib/pry_toggle/exec.rb
CHANGED
@@ -1,15 +1,28 @@
|
|
1
|
-
require 'pry'
|
2
1
|
require 'pry_toggle'
|
3
2
|
|
4
3
|
module PryToggle
|
5
4
|
class Exec
|
6
5
|
def initialize(args)
|
7
|
-
args.first =~ /\A(.+):(\d+?)\z/
|
8
|
-
|
6
|
+
if args.first =~ /\A(.+):(\d+?)\z/
|
7
|
+
@service = PryToggle::Service.new($1, $2.to_i, '', "binding.pry\n")
|
8
|
+
else
|
9
|
+
puts <<-DOC
|
10
|
+
=== Format should be ===
|
11
|
+
$ pry-tgl exmain.rb:10
|
12
|
+
|
13
|
+
OR
|
14
|
+
|
15
|
+
$ pry-tgl exmain.rb#method_name
|
16
|
+
DOC
|
17
|
+
end
|
9
18
|
end
|
10
19
|
|
11
20
|
def execute!
|
12
21
|
@service.execute
|
13
22
|
end
|
23
|
+
|
24
|
+
def executable?
|
25
|
+
!!@service
|
26
|
+
end
|
14
27
|
end
|
15
28
|
end
|
data/lib/pry_toggle/service.rb
CHANGED
@@ -4,19 +4,24 @@ module PryToggle
|
|
4
4
|
class Service < ::Struct.new(:origin_path, :line_num, :mth_name, :str)
|
5
5
|
|
6
6
|
def execute
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
7
|
+
File.open(tmp_file_path, 'w') do |d|
|
8
|
+
File.open(abs_file_path, 'r') do |o|
|
9
|
+
o.each.with_index(1) do |line, i|
|
10
|
+
if (line == str)
|
11
|
+
else
|
12
|
+
d << str if i == line_num
|
13
|
+
d << line
|
14
|
+
end
|
15
|
+
d << str if line =~ %r|def( +)#{mth_name}|
|
16
|
+
end
|
14
17
|
end
|
15
18
|
end
|
16
|
-
f.close
|
17
|
-
tempfile.close
|
18
19
|
|
19
20
|
FileUtils.mv(tmp_file_path, abs_file_path)
|
21
|
+
rescue Errno::ENOENT
|
22
|
+
puts "No such file - #{origin_path}"
|
23
|
+
ensure
|
24
|
+
FileUtils.rm_f(tmp_file_path)
|
20
25
|
end
|
21
26
|
|
22
27
|
private
|
data/lib/pry_toggle/version.rb
CHANGED
data/test/test_pry_toggle.rb
CHANGED
@@ -1,16 +1,49 @@
|
|
1
1
|
require 'minitest_helper'
|
2
2
|
require 'pry'
|
3
3
|
class TestPryToggle < MiniTest::Unit::TestCase
|
4
|
-
def
|
4
|
+
def test_insert_by_line_num
|
5
5
|
test_file_path = "./test/test_files/test.rb"
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
File.open(test_file_path, 'w') do |t|
|
7
|
+
10.times { t << "test\n" }
|
8
|
+
end
|
9
|
+
|
10
|
+
service = PryToggle::Service.new(test_file_path, 6, '', "binding.pry\n")
|
10
11
|
service.execute
|
11
12
|
|
12
13
|
assert_equal "test\ntest\ntest\ntest\ntest\nbinding.pry\ntest\ntest\ntest\ntest\ntest\n", File.open(test_file_path, 'r').read
|
13
14
|
|
14
15
|
FileUtils.rm(test_file_path)
|
15
16
|
end
|
17
|
+
|
18
|
+
def test_remove_by_line_num
|
19
|
+
test_file_path = "./test/test_files/test.rb"
|
20
|
+
File.open(test_file_path, 'w') do |t|
|
21
|
+
5.times { t << "test\n" }
|
22
|
+
t << "binding.pry\n"
|
23
|
+
5.times { t << "test\n" }
|
24
|
+
end
|
25
|
+
|
26
|
+
service = PryToggle::Service.new(test_file_path, nil, '', "binding.pry\n")
|
27
|
+
service.execute
|
28
|
+
|
29
|
+
assert_equal "test\ntest\ntest\ntest\ntest\ntest\ntest\ntest\ntest\ntest\n", File.open(test_file_path, 'r').read
|
30
|
+
|
31
|
+
FileUtils.rm(test_file_path)
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_insert_by_mth_name
|
35
|
+
test_file_path = "./test/test_files/test.rb"
|
36
|
+
File.open(test_file_path, 'w') do |t|
|
37
|
+
5.times { t << "test\n" }
|
38
|
+
t << "def test_method\n"
|
39
|
+
5.times { t << "test\n" }
|
40
|
+
end
|
41
|
+
|
42
|
+
service = PryToggle::Service.new(test_file_path, nil, "test_method", "binding.pry\n")
|
43
|
+
service.execute
|
44
|
+
|
45
|
+
assert_equal "test\ntest\ntest\ntest\ntest\ndef test_method\nbinding.pry\ntest\ntest\ntest\ntest\ntest\n", File.open(test_file_path, 'r').read
|
46
|
+
|
47
|
+
FileUtils.rm(test_file_path)
|
48
|
+
end
|
16
49
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pry-toggle
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- gogotanaka
|
@@ -52,14 +52,17 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
-
description: '
|
55
|
+
description: ' All you need to do is copy message from command line like "main.rb:9"
|
56
|
+
and run `pry-tgl main.rb:9` from command line! '
|
56
57
|
email:
|
57
58
|
- mail@tanakakazuki.com
|
58
59
|
executables:
|
60
|
+
- pry-tgl
|
59
61
|
- pry-toggle
|
60
62
|
extensions: []
|
61
63
|
extra_rdoc_files: []
|
62
64
|
files:
|
65
|
+
- bin/pry-tgl
|
63
66
|
- bin/pry-toggle
|
64
67
|
- lib/pry_toggle.rb
|
65
68
|
- lib/pry_toggle/exec.rb
|
@@ -90,5 +93,5 @@ rubyforge_project:
|
|
90
93
|
rubygems_version: 2.2.2
|
91
94
|
signing_key:
|
92
95
|
specification_version: 4
|
93
|
-
summary: Toggle "binding.pry" easily from command line.
|
96
|
+
summary: Toggle breakpoints "binding.pry" easily from command line.
|
94
97
|
test_files: []
|