module RailsStats::Util
Public Instance Methods
calculate_directory_statistics(directory, pattern = /.*\.(rb|js|coffee|feature)$/)
click to toggle source
# File lib/rails_stats/util.rb, line 78 def calculate_directory_statistics(directory, pattern = /.*\.(rb|js|coffee|feature)$/) stats = CodeStatisticsCalculator.new Dir.foreach(directory) do |file_name| path = "#{directory}/#{file_name}" if File.directory?(path) && (/^\./ !~ file_name) stats.add(calculate_directory_statistics(path, pattern)) end next unless file_name =~ pattern stats.add_by_file_path(path) end stats end
calculate_file_statistics(file, type = :code, &block)
click to toggle source
# File lib/rails_stats/util.rb, line 39 def calculate_file_statistics(file, type = :code, &block) stats = CodeStatisticsCalculator.new files = [file].flatten files.each do |path| stats.add_by_file_path(path) end stats end
calculate_projects(*args)
click to toggle source
# File lib/rails_stats/util.rb, line 5 def calculate_projects(*args) projects = {} children = [args.pop].flatten parent = args.flatten children.each do |dirname| child_folder_pattern = File.join(*(parent.dup + [dirname])) Dir[child_folder_pattern].each do |marker_path| next if marker_path =~ /\/vendor\// projects[File.absolute_path(File.dirname(marker_path))] = true end end out = projects.keys # TODO: make sure none are children of other ones in there out end
calculate_statistics(directories, type = :code) { |dir_path| ... }
click to toggle source
# File lib/rails_stats/util.rb, line 51 def calculate_statistics(directories, type = :code, &block) out = {} directories = [directories].flatten is_test = (type.to_s == "test") directories.each do |dir_path| next unless File.directory?(dir_path) key = nil if block_given? key = yield(dir_path) end key = path_to_name(dir_path, is_test) if !key || key.length == 0 out[key] ||= CodeStatisticsCalculator.new(is_test) out[key].add(calculate_directory_statistics(dir_path)) end out.keys.each do |key| out.delete(key) if out[key].lines == 0 end out end
path_to_name(path, is_test)
click to toggle source
# File lib/rails_stats/util.rb, line 96 def path_to_name(path, is_test) folder = File.basename(path) folder = Inflector.humanize(folder) folder = Inflector.titleize(folder) if is_test folder = Inflector.singularize(folder) folder = "#{folder} Tests" else folder = Inflector.pluralize(folder) end folder end