bigfiles 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e71fe3cba3ab92d223331defd4474e8d4fbd4594
4
+ data.tar.gz: 98a7bfee695fed96d09cc3bfdf25317d27df4f22
5
+ SHA512:
6
+ metadata.gz: d3d460aca1aa03aa8ab22a2485243aa677210b544edfb40e7f367bd3480a1d325f91223360d6855c667dab6a87d9f24a3da8bf0f80ab5ca7ce5b3037aa0bd80e
7
+ data.tar.gz: 17d3b119ff8c75e1faa6f7fa5591ade7486b521ae4443bc2c90b1e4d609ce3c5aad2f07490d2d06ebf8d2564efafe16e491b2687e72496c6a46b54cef0c6cbb9
data/Rakefile ADDED
@@ -0,0 +1,30 @@
1
+ require 'rspec/core/rake_task'
2
+ require 'quality/rake/task'
3
+ require 'bundler/gem_tasks'
4
+
5
+ Quality::Rake::Task.new do |task|
6
+ task.skip_tools = ['reek']
7
+ task.output_dir = 'metrics'
8
+ end
9
+
10
+ desc 'Run specs'
11
+ RSpec::Core::RakeTask.new(:spec) do |task|
12
+ task.pattern = 'spec/**/*_spec.rb'
13
+ task.rspec_opts = '--format doc'
14
+ end
15
+
16
+ desc 'Run features'
17
+ RSpec::Core::RakeTask.new(:feature) do |task|
18
+ task.pattern = 'feature/**/*_spec.rb'
19
+ task.rspec_opts = "--format doc"
20
+ end
21
+
22
+ task :clear_metrics do |_t|
23
+ ret =
24
+ system('git checkout coverage/.last_run.json metrics/*_high_water_mark')
25
+ fail unless ret
26
+ end
27
+
28
+ desc 'Default: Run specs and check quality.'
29
+ task localtest: [:clear_metrics, :spec, :feature, :quality]
30
+ task default: [:localtest]
data/bigfiles.gemspec ADDED
@@ -0,0 +1,34 @@
1
+ # ; -*-Ruby-*-
2
+ # -*- encoding: utf-8 -*-
3
+ $LOAD_PATH.push File.join(File.dirname(__FILE__), 'lib')
4
+ require 'bigfiles/version'
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = 'bigfiles'
8
+ s.version = BigFiles::VERSION
9
+
10
+ s.authors = ['Vince Broz']
11
+ s.description = 'bigfiles finds the largest source files in your project ' \
12
+ 'and reports on them'
13
+ s.email = ['vince@broz.cc']
14
+ # s.executables = ["bigfiles"]
15
+ # s.extra_rdoc_files = ["CHANGELOG", "License.txt"]
16
+ s.license = 'MIT'
17
+ s.files = Dir['License.txt', 'README.md',
18
+ 'Rakefile',
19
+ # "bin/bigfiles",
20
+ '{lib}/**/*',
21
+ 'bigfiles.gemspec'] & `git ls-files -z`.split("\0")
22
+ # s.rdoc_options = ["--main", "README.md"]
23
+ s.require_paths = ['lib']
24
+ s.homepage = 'http://github.com/apiology/bigfiles'
25
+ # s.rubyforge_project = %q{bigfiles}
26
+ s.rubygems_version = '1.3.6'
27
+ s.summary = 'Finds largest source files in a project'
28
+
29
+ s.add_development_dependency('bundler')
30
+ s.add_development_dependency('rake')
31
+ s.add_development_dependency('quality')
32
+ s.add_development_dependency('rspec')
33
+ s.add_development_dependency('simplecov')
34
+ end
@@ -0,0 +1,25 @@
1
+ module BigFiles
2
+ # Encapsulates a file which has a certain number of lines
3
+ class FileWithLines
4
+ attr_reader :filename
5
+
6
+ def initialize(filename, file_opener: File)
7
+ @filename = filename
8
+ @file_opener = file_opener
9
+ end
10
+
11
+ def <=>(other)
12
+ num_lines <=> other.num_lines
13
+ end
14
+
15
+ def num_lines
16
+ num_lines = 0
17
+ @file_opener.open(filename, 'r') do |file|
18
+ file.each_line do |_line|
19
+ num_lines += 1
20
+ end
21
+ end
22
+ num_lines
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,20 @@
1
+ require 'find'
2
+
3
+ module BigFiles
4
+ # Finds source code files in the current directory
5
+ class SourceCodeFinder
6
+ def initialize(filefind: Find)
7
+ @filefind = filefind
8
+ end
9
+
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
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,4 @@
1
+ # Tool to find the largest source files in your project
2
+ module BigFiles
3
+ VERSION = '0.0.1'
4
+ end
data/lib/bigfiles.rb ADDED
@@ -0,0 +1,43 @@
1
+ require_relative 'bigfiles/source_code_finder'
2
+ require_relative 'bigfiles/file_with_lines'
3
+
4
+ # Simple tool to find the largest source files in your project.
5
+ module BigFiles
6
+ # Simple tool to find the largest source files in your project.
7
+ class BigFiles
8
+ def initialize(args,
9
+ io: Kernel,
10
+ exiter: Kernel,
11
+ 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
17
+ @source_file_finder = source_file_finder
18
+ end
19
+
20
+ def usage
21
+ @io.puts "USAGE: bigfiles [-n <top n files>]\n"
22
+ @exiter.exit 1
23
+ end
24
+
25
+ def find_analyze_and_report_on_files
26
+ file_list = @source_file_finder.find
27
+ files_with_lines = file_list.map do |filename|
28
+ @file_with_lines.new(filename)
29
+ end
30
+ files_with_lines.sort.reverse[0..2].each do |file|
31
+ @io.puts "#{file.num_lines}: #{file.filename}"
32
+ end
33
+ end
34
+
35
+ def run
36
+ if @args[0] == '-h'
37
+ usage
38
+ else
39
+ find_analyze_and_report_on_files
40
+ end
41
+ end
42
+ end
43
+ end
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bigfiles
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Vince Broz
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-04-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: quality
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: bigfiles finds the largest source files in your project and reports on
84
+ them
85
+ email:
86
+ - vince@broz.cc
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - Rakefile
92
+ - bigfiles.gemspec
93
+ - lib/bigfiles.rb
94
+ - lib/bigfiles/file_with_lines.rb
95
+ - lib/bigfiles/source_code_finder.rb
96
+ - lib/bigfiles/version.rb
97
+ homepage: http://github.com/apiology/bigfiles
98
+ licenses:
99
+ - MIT
100
+ metadata: {}
101
+ post_install_message:
102
+ rdoc_options: []
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - '>='
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ requirements: []
116
+ rubyforge_project:
117
+ rubygems_version: 2.4.6
118
+ signing_key:
119
+ specification_version: 4
120
+ summary: Finds largest source files in a project
121
+ test_files: []