pry-toggle 0.0.2 → 0.0.3

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
  SHA1:
3
- metadata.gz: c50c1a062d4f71f37e5e651d8c7b38326d6acc17
4
- data.tar.gz: 14c7b2a564de915689871920f3df37e2992badf9
3
+ metadata.gz: 2bb7c24419c7ab585abcdbe487475dd24d12a680
4
+ data.tar.gz: 9ec8430d6e2bbb1c0c1deb773527d227ab26934f
5
5
  SHA512:
6
- metadata.gz: 001f54a7b6f663808f2914882811ae84fc5a5354dc7862107345f01c6e06862aaacdffd783c7f25259ac204281c4da1fd7e4aebdc18c625f218574e3159c555a
7
- data.tar.gz: 51767b9d3c296e9882fe9a92d394263834fa559f4e6ac5d0a5f08194fd8a4753e4280fbcca9cd434043d3a6cd49b604673e644f9ea1513a5eb8a8a15db475d12
6
+ metadata.gz: 776cdad068d5a30652c97092ed6df3999dd39d402badd8f0e2f4ef34e0876ab2e5901231555b16a5f2884291153459de4777fbd442fa63ada87bc32cf21a9b42
7
+ data.tar.gz: a5464d5431b7479f0a9fc854be54d7106fbcc87e82e9956722038062e79f194a5440507078942d7ea5d4932f1a9db705279ce3b82c87f08adbdffa8911f18247
@@ -3,5 +3,5 @@
3
3
  $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
4
4
  require 'pry_toggle/exec'
5
5
 
6
- opts = PryToggle::Exec.new(ARGV)
6
+ opts = PryToggle::Exec.new(ARGV, on: false)
7
7
  opts.execute! if opts.executable?
@@ -3,5 +3,5 @@
3
3
  $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
4
4
  require 'pry_toggle/exec'
5
5
 
6
- opts = PryToggle::Exec.new(ARGV)
6
+ opts = PryToggle::Exec.new(ARGV, on: true)
7
7
  opts.execute! if opts.executable?
@@ -2,18 +2,23 @@ require 'pry_toggle'
2
2
 
3
3
  module PryToggle
4
4
  class Exec
5
- def initialize(args)
5
+ def initialize(args, hash)
6
6
  if args.first =~ /\A(.+):(\d+?)\z/
7
- @service = PryToggle::Service.new($1, $2.to_i, '', "binding.pry\n")
7
+ @service = PryToggle::Service.new($1, $2.to_i, '', "binding.pry\n", hash[:on])
8
8
  else
9
- puts <<-DOC
10
- === Format should be ===
11
- $ pry-tgl exmain.rb:10
9
+ if hash[:on]
10
+ puts <<-DOC
11
+ === Invalid command format. should be like that. ===
12
+ $ pry-on exmain.rb:10
13
+ DOC
14
+ else
15
+ puts <<-DOC
16
+ === Invalid command format. should be like that. ===
17
+ $ pry-off exmain.rb:10
18
+ DOC
19
+ end
12
20
 
13
- OR
14
21
 
15
- $ pry-tgl exmain.rb#method_name
16
- DOC
17
22
  end
18
23
  end
19
24
 
@@ -1,18 +1,21 @@
1
1
  require 'fileutils'
2
2
 
3
3
  module PryToggle
4
- class Service < ::Struct.new(:origin_path, :line_num, :mth_name, :str)
4
+ class Service < ::Struct.new(:origin_path, :line_num, :mth_name, :str, :on)
5
5
 
6
6
  def execute
7
7
  File.open(tmp_file_path, 'w') do |d|
8
8
  File.open(abs_file_path, 'r') do |o|
9
- o.each.with_index(1) do |line, i|
10
- if (line == str)
11
- else
9
+ if on
10
+ o.each.with_index(1) do |line, i|
12
11
  d << str if i == line_num
13
12
  d << line
13
+ d << str if line =~ %r|def( +)#{mth_name}|
14
+ end
15
+ else
16
+ o.each.with_index(1) do |line, i|
17
+ d << line unless (i == line_num || line_num.nil?) && line == str
14
18
  end
15
- d << str if line =~ %r|def( +)#{mth_name}|
16
19
  end
17
20
  end
18
21
  end
@@ -1,3 +1,3 @@
1
1
  module PryToggle
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -7,7 +7,7 @@ class TestPryToggle < MiniTest::Unit::TestCase
7
7
  10.times { t << "test\n" }
8
8
  end
9
9
 
10
- service = PryToggle::Service.new(test_file_path, 6, '', "binding.pry\n")
10
+ service = PryToggle::Service.new(test_file_path, 6, '', "binding.pry\n", true)
11
11
  service.execute
12
12
 
13
13
  assert_equal "test\ntest\ntest\ntest\ntest\nbinding.pry\ntest\ntest\ntest\ntest\ntest\n", File.open(test_file_path, 'r').read
@@ -23,7 +23,7 @@ class TestPryToggle < MiniTest::Unit::TestCase
23
23
  5.times { t << "test\n" }
24
24
  end
25
25
 
26
- service = PryToggle::Service.new(test_file_path, nil, '', "binding.pry\n")
26
+ service = PryToggle::Service.new(test_file_path, nil, '', "binding.pry\n", false)
27
27
  service.execute
28
28
 
29
29
  assert_equal "test\ntest\ntest\ntest\ntest\ntest\ntest\ntest\ntest\ntest\n", File.open(test_file_path, 'r').read
@@ -39,7 +39,7 @@ class TestPryToggle < MiniTest::Unit::TestCase
39
39
  5.times { t << "test\n" }
40
40
  end
41
41
 
42
- service = PryToggle::Service.new(test_file_path, nil, "test_method", "binding.pry\n")
42
+ service = PryToggle::Service.new(test_file_path, nil, "test_method", "binding.pry\n", true)
43
43
  service.execute
44
44
 
45
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
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.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - gogotanaka
@@ -57,13 +57,13 @@ description: ' All you need to do is copy message from command line like "main.r
57
57
  email:
58
58
  - mail@tanakakazuki.com
59
59
  executables:
60
- - pry-tgl
61
- - pry-toggle
60
+ - pry-on
61
+ - pry-off
62
62
  extensions: []
63
63
  extra_rdoc_files: []
64
64
  files:
65
- - bin/pry-tgl
66
- - bin/pry-toggle
65
+ - bin/pry-off
66
+ - bin/pry-on
67
67
  - lib/pry_toggle.rb
68
68
  - lib/pry_toggle/exec.rb
69
69
  - lib/pry_toggle/service.rb