bigfiles 0.0.2 → 0.0.3

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: 3cd6c9d1d07da0ad571fe464f1092a645c36a28b
4
- data.tar.gz: 577b578a937e1425c6b0b71c19b26849d78e0ff7
3
+ metadata.gz: d6cefc72283ccb733aac758efef36fb092e9ab06
4
+ data.tar.gz: c01b4493074f206eb84f4e3b85139331235228b6
5
5
  SHA512:
6
- metadata.gz: e6fb26bd54301c2b13255d0ef0079bc50ad55793f3f88cc7b6b02f040af6873c713748b325f16dba1dea4ec536df509dd516f1754fddf95a9bb791e3ee2b7920
7
- data.tar.gz: a88c51610683c5412b2ee9b6c6ef79b9d70f52475e5c4b29a98590f7f3c6714e3123ceb1a05b59027d8c458260645c66c84d317b5aeda167b9d40097f7397df1
6
+ metadata.gz: 9f2c59d88b45fa32bd4381362a7a533bbaac513c02f43e4a7b59f17b5dd967a8f2209ca7613d2c207e01069ce39924e5e2c278807222c4ee60cde9b84fc8f572
7
+ data.tar.gz: c56569877f892751b3d5047610c72ba827d9a1942dc2fecd5dc96fa22f267e113c10990636e23f8fc059b9d82c9cce966aecbeab04e9a1482be0a1867686903d
data/lib/bigfiles.rb CHANGED
@@ -1,3 +1,5 @@
1
+ require 'optparse'
2
+
1
3
  require_relative 'bigfiles/source_code_finder'
2
4
  require_relative 'bigfiles/file_with_lines'
3
5
 
@@ -9,12 +11,40 @@ module BigFiles
9
11
  io: Kernel,
10
12
  exiter: Kernel,
11
13
  file_with_lines: FileWithLines,
12
- source_file_finder: SourceCodeFinder.new)
13
- @args = args
14
- @io = io
15
- @exiter = exiter
16
- @file_with_lines = file_with_lines
14
+ source_file_finder: SourceCodeFinder.new,
15
+ option_parser: OptionParser)
16
+ @io, @exiter, @file_with_lines = io, exiter, file_with_lines
17
17
  @source_file_finder = source_file_finder
18
+ @option_parser = option_parser
19
+ @options = parse_options(args)
20
+ end
21
+
22
+ def parse_options(args)
23
+ options = nil
24
+ @option_parser.new do |opts|
25
+ options = setup_options(opts)
26
+ end.parse!(args)
27
+ options
28
+ end
29
+
30
+ DEFAULT_GLOB =
31
+ '{app,lib,test,spec,feature}/**/*.{rb,swift,cpp,c,java,py}'
32
+
33
+ def glob
34
+ @options[:glob] || DEFAULT_GLOB
35
+ end
36
+
37
+ def setup_options(opts)
38
+ options = {}
39
+ opts.banner = 'Usage: bigfiles [options]'
40
+ opts.on('-g glob here', '--glob',
41
+ "Which files to parse - default is #{DEFAULT_GLOB}") do |v|
42
+ options[:glob] = v
43
+ end
44
+ opts.on('-h', '--help', 'This message') do |_|
45
+ options[:help] = true
46
+ end
47
+ options
18
48
  end
19
49
 
20
50
  def usage
@@ -23,7 +53,7 @@ module BigFiles
23
53
  end
24
54
 
25
55
  def find_analyze_and_report_on_files
26
- file_list = @source_file_finder.find
56
+ file_list = @source_file_finder.find(glob)
27
57
  files_with_lines = file_list.map do |filename|
28
58
  @file_with_lines.new(filename)
29
59
  end
@@ -33,7 +63,7 @@ module BigFiles
33
63
  end
34
64
 
35
65
  def run
36
- if @args[0] == '-h'
66
+ if @options[:help]
37
67
  usage
38
68
  else
39
69
  find_analyze_and_report_on_files
@@ -3,18 +3,14 @@ require 'find'
3
3
  module BigFiles
4
4
  # Finds source code files in the current directory
5
5
  class SourceCodeFinder
6
- def initialize(filefind: Find)
6
+ def initialize(filefind: Find,
7
+ globber: Dir)
7
8
  @filefind = filefind
9
+ @globber = globber
8
10
  end
9
11
 
10
- def find
11
- files = []
12
- @filefind.find('.') do |path|
13
- files << path if path =~ /.*\.rb$/ || path =~ /.*\.swift$/
14
- end
15
- files.map do |filename|
16
- filename.sub(/^.\//, '')
17
- end
12
+ def find(glob)
13
+ @globber.glob(glob)
18
14
  end
19
15
  end
20
16
  end
@@ -1,4 +1,4 @@
1
1
  # Tool to find the largest source files in your project
2
2
  module BigFiles
3
- VERSION = '0.0.2'
3
+ VERSION = '0.0.3'
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bigfiles
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
  - Vince Broz