byepry 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/byepry +2 -1
  3. data/lib/byepry.rb +34 -15
  4. metadata +17 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2b5d097323681ad650646d2f2e8e83d73a08fef6
4
- data.tar.gz: a489b43b3d3708774911709ce0b91f64c01b5563
3
+ metadata.gz: b1b0e2ff6aa4459966f9eb3be5597a5df1e2d5a2
4
+ data.tar.gz: 6b1a9506350e4443f041971106676c8b907015fc
5
5
  SHA512:
6
- metadata.gz: 2247f38fb46c606403fc5a6045ccf9fb747d92c2e7305d004950d1f2b33ea9a5d152b7c6d1672025939db328dbba0ef81c0b734ef91041672c58a8b30d5bde3b
7
- data.tar.gz: 38e4c00d4736593e05f01a249d34a0754d73e8161657251c1cfe8b11920719ade4c6d376c934d109e722632e7769de09321ab1efaa70f19736d3d80e519670f4
6
+ metadata.gz: 2dae7ac7612270851a464d22320f731075a74089a3e8d750601cdcaef7e99ada6b57b3a4ffecaa62a8b49585e990aefc15bf806db9bf3e71b8c2600748015d9d
7
+ data.tar.gz: 7aa45014e28b60ed0185333e105945290b39913bc6cd4ed618def7e59d7c98951ddd228ff54cc2ee13526ac484fbdd34d7f4507a059fb8102694234496cd7443
data/bin/byepry CHANGED
@@ -3,4 +3,5 @@
3
3
  require 'fileutils'
4
4
  require 'tempfile'
5
5
  require 'byepry'
6
- Byepry.go
6
+
7
+ Byepry.new(ARGV).go
@@ -4,29 +4,48 @@ require 'tempfile'
4
4
  require 'colorize'
5
5
 
6
6
  class Byepry
7
- def self.go
7
+ def initialize(options = [])
8
+ @options = options
9
+ end
10
+
11
+ def go
8
12
  Find.find('.') do |path|
9
- next unless path =~ /.*\.rb$/
13
+ next unless path =~ /.*\.(rb|erb)$/
14
+
10
15
  file = File.open(path, 'r+')
11
16
  # Open a temporary file
12
17
  tmp = Tempfile.new('extract')
18
+ changed_file = remove_pry_from_file(file, tmp)
13
19
 
14
- changed_file = false
15
- line_number = 0
16
- # Write good lines to temporary file
17
- open(path, 'r').each do |l|
18
- line_number += 1
19
- if l.include? 'binding.pry'
20
- changed_file = true
21
- puts "Removed pry from File: #{path} Line: #{line_number}".green
22
- end
23
- tmp << l unless l.include? 'binding.pry'
24
- end
25
-
26
- # Close tmp
27
20
  tmp.close
28
21
  # Move temp file to origin if file changed
29
22
  FileUtils.mv(tmp.path, path) if changed_file
30
23
  end
31
24
  end
25
+
26
+ def remove_pry_from_file(file, tmp)
27
+ changed_file = false
28
+ line_number = 0
29
+
30
+ # Write good lines to temporary file
31
+ file.each do |line|
32
+ line_number += 1
33
+
34
+ if condition_to_remove? line
35
+ changed_file = true
36
+ puts "Removed pry from File: #{file.path} Line: #{line_number}".green
37
+ else
38
+ tmp << line
39
+ end
40
+ end
41
+
42
+ changed_file
43
+ end
44
+
45
+ def condition_to_remove?(line)
46
+ # Remove all 'binding.pry'
47
+ return line.include?('binding.pry') if @options.empty?
48
+ # Ignore commented lines
49
+ return line.include?('binding.pry') && !line.strip.start_with?('#') if @options[0] == '-i'
50
+ end
32
51
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: byepry
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Othmane EL KESRI
@@ -9,7 +9,21 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
  date: 2018-05-11 00:00:00.000000000 Z
12
- dependencies: []
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: colorize
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.8.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.8.1
13
27
  description: A simple gem that removes the 'binding.pry' lines
14
28
  email: elkesri.othmane@gmail.com
15
29
  executables:
@@ -39,7 +53,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
39
53
  version: '0'
40
54
  requirements: []
41
55
  rubyforge_project:
42
- rubygems_version: 2.6.11
56
+ rubygems_version: 2.6.14
43
57
  signing_key:
44
58
  specification_version: 4
45
59
  summary: ByePry!