pry-toggle 0.0.1 → 0.0.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
  SHA1:
3
- metadata.gz: 9735f5c63dc772693ff6f47de28100ab04418b6e
4
- data.tar.gz: 2bf9599c7d6505a2b8045675065188cc108b1bab
3
+ metadata.gz: c50c1a062d4f71f37e5e651d8c7b38326d6acc17
4
+ data.tar.gz: 14c7b2a564de915689871920f3df37e2992badf9
5
5
  SHA512:
6
- metadata.gz: 53900ec8f5c1ef2b46fc306145f5ee6f60319b050e44166203406bc4a84f07a290dd7188a5bb715c8f76307f761d16424135d6fe9eb28fc378242c9c7e6cee87
7
- data.tar.gz: c20c7573ec05e475603d3f24b8c432d1c42919682d460c766018dba7ebcacb8f115f8abbfd8615e92418438c9b4c703dee1f1ed084318e8de8f422ccf9527e61
6
+ metadata.gz: 001f54a7b6f663808f2914882811ae84fc5a5354dc7862107345f01c6e06862aaacdffd783c7f25259ac204281c4da1fd7e4aebdc18c625f218574e3159c555a
7
+ data.tar.gz: 51767b9d3c296e9882fe9a92d394263834fa559f4e6ac5d0a5f08194fd8a4753e4280fbcca9cd434043d3a6cd49b604673e644f9ea1513a5eb8a8a15db475d12
data/bin/pry-tgl ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
4
+ require 'pry_toggle/exec'
5
+
6
+ opts = PryToggle::Exec.new(ARGV)
7
+ opts.execute! if opts.executable?
data/bin/pry-toggle CHANGED
@@ -4,4 +4,4 @@ $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
4
4
  require 'pry_toggle/exec'
5
5
 
6
6
  opts = PryToggle::Exec.new(ARGV)
7
- opts.execute!
7
+ opts.execute! if opts.executable?
@@ -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
- @service = PryToggle::Service.new($1, $2.to_i, '', "binding.pry\n")
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
@@ -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
- fail '' unless origin_path
8
- tempfile = File.open(tmp_file_path, 'w')
9
- f = File.open(abs_file_path, 'r')
10
- f.each.with_index(1) do |line, i|
11
- tempfile << line
12
- if i == line_num
13
- tempfile << str
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
@@ -1,3 +1,3 @@
1
1
  module PryToggle
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -1,16 +1,49 @@
1
1
  require 'minitest_helper'
2
2
  require 'pry'
3
3
  class TestPryToggle < MiniTest::Unit::TestCase
4
- def test_general
4
+ def test_insert_by_line_num
5
5
  test_file_path = "./test/test_files/test.rb"
6
- test_file = File.open(test_file_path, 'w')
7
- 10.times { test_file << "test\n" }
8
- test_file.close
9
- service = PryToggle::Service.new(test_file_path, 5, '', "binding.pry\n")
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.1
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: ' Toggle "binding.pry" easily from command line. '
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: []