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 +4 -4
- data/lib/bigfiles.rb +37 -7
- data/lib/bigfiles/source_code_finder.rb +5 -9
- data/lib/bigfiles/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d6cefc72283ccb733aac758efef36fb092e9ab06
|
4
|
+
data.tar.gz: c01b4493074f206eb84f4e3b85139331235228b6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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 @
|
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
|
-
|
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
|
data/lib/bigfiles/version.rb
CHANGED