Class: CodeCounter::Engine
- Inherits:
-
Object
- Object
- CodeCounter::Engine
- Defined in:
- lib/code_counter/engine.rb
Constant Summary collapse
- BIN_DIRECTORIES =
Set.new
- STATS_DIRECTORIES =
[]
- TEST_TYPES =
Set.new
- FILTER =
Internals
/.*\.(rb|feature|rake)$/
Instance Attribute Summary collapse
-
#print_buffer ⇒ Object
readonly
Returns the value of attribute print_buffer.
Class Method Summary collapse
- .add_path(key, directory, recursive = true, is_bin_dir = false) ⇒ Object
- .add_test_group(key) ⇒ Object
-
.clear! ⇒ Object
Mechanisms for configuring the behavior of this tool.
-
.init! ⇒ Object
Default configuration.
Instance Method Summary collapse
- #coalesce_pairs(pairs) ⇒ Object
- #collect_files_to_ignore(ignore_file_globs) ⇒ Object
-
#initialize(ignore_file_globs = []) ⇒ Engine
constructor
A new instance of Engine.
- #to_s ⇒ Object
Constructor Details
#initialize(ignore_file_globs = []) ⇒ Engine
Returns a new instance of Engine.
70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/code_counter/engine.rb', line 70 def initialize(ignore_file_globs = []) @bin_dirs = BIN_DIRECTORIES.dup @pairs = STATS_DIRECTORIES.select { |pair| File.directory?(pair[1]) } @print_buffer = "" @ignore_files = collect_files_to_ignore(ignore_file_globs) @pairs = coalesce_pairs(@pairs) @statistics = calculate_statistics @total = (@pairs.length > 1) ? calculate_total : nil end |
Instance Attribute Details
#print_buffer ⇒ Object (readonly)
Returns the value of attribute print_buffer.
68 69 70 |
# File 'lib/code_counter/engine.rb', line 68 def print_buffer @print_buffer end |
Class Method Details
.add_path(key, directory, recursive = true, is_bin_dir = false) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/code_counter/engine.rb', line 18 def self.add_path(key, directory, recursive=true, is_bin_dir=false) directory = File.(directory) if File.directory?(directory) STATS_DIRECTORIES << [key, directory] BIN_DIRECTORIES << directory if is_bin_dir if(recursive) Dir.entries(directory). reject { |dirent| dirent =~ /^\.\.?$/ }. map { |dirent| File.join(directory, dirent) }. reject { |dirent| !File.directory?(dirent) }. each { |dirent| add_path(key, dirent, recursive, is_bin_dir) } end end end |
.add_test_group(key) ⇒ Object
33 34 35 |
# File 'lib/code_counter/engine.rb', line 33 def self.add_test_group(key) TEST_TYPES << key end |
.clear! ⇒ Object
Mechanisms for configuring the behavior of this tool
12 13 14 15 16 |
# File 'lib/code_counter/engine.rb', line 12 def self.clear! BIN_DIRECTORIES.clear STATS_DIRECTORIES.clear TEST_TYPES.clear end |
.init! ⇒ Object
Default configuration
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/code_counter/engine.rb', line 41 def self.init! add_path("Controllers", "app/controllers") add_path("Mailers", "app/mailers") add_path("Models", "app/models") add_path("Views", "app/views") add_path("Helpers", "app/helpers") add_path("Binaries", "bin", true, true) add_path("Binaries", "script", true, true) add_path("Binaries", "scripts", true, true) add_path("Libraries", "lib") add_path("Source", "source") add_path("Source", "src") add_path("Unit tests", "test") add_path("RSpec specs", "spec") add_path("Features", "features") add_test_group("Unit tests") add_test_group("RSpec specs") add_test_group("Features") end |
Instance Method Details
#coalesce_pairs(pairs) ⇒ Object
82 83 84 85 86 87 88 89 90 91 |
# File 'lib/code_counter/engine.rb', line 82 def coalesce_pairs(pairs) groups = {} paths_seen = {} pairs.each do |pair| next if(paths_seen[pair.last]) paths_seen[pair.last] = true (groups[pair.first] ||= Set.new) << pair.last end return groups end |
#collect_files_to_ignore(ignore_file_globs) ⇒ Object
93 94 95 96 97 98 99 |
# File 'lib/code_counter/engine.rb', line 93 def collect_files_to_ignore(ignore_file_globs) files_to_remove = [] ignore_file_globs.each do |glob| files_to_remove.concat(Dir[glob]) end files_to_remove.map { |filepath| File.(filepath) } end |
#to_s ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/code_counter/engine.rb', line 101 def to_s @print_buffer = '' print_header @pairs.each { |pair| print_line(pair.first, @statistics[pair.first]) } print_splitter if @total print_line("Total", @total) print_splitter end print_code_test_stats @print_buffer end |