class Serum::Rails::CodeScanner
Constants
- ANYTHING
- DEBUG
- DEFAULT_FOLDERS
Public Class Methods
new(root)
click to toggle source
# File lib/serum/rails/code_scanner.rb, line 9 def initialize(root) @root = root end
Public Instance Methods
count_lines(options = {})
click to toggle source
# File lib/serum/rails/code_scanner.rb, line 13 def count_lines(options = {}) pattern = options.fetch(:pattern, ANYTHING) folders = Array.wrap(options.fetch(:folders, DEFAULT_FOLDERS)) type_selection = TypeSelection.new(options[:types]) paths(folders, type_selection).sort.sum do |path| count_occurrences(path, pattern) end end
Private Instance Methods
count_occurrences(path, pattern)
click to toggle source
# File lib/serum/rails/code_scanner.rb, line 35 def count_occurrences(path, pattern) content = File.read(path) or raise "Could not read file: #{path}" #if path =~ /session_store/ # puts "-----" # puts content # puts "-----" #end matches = content.scan(pattern) matches.each { |match| puts "#{path}: #{match}" } if DEBUG matches.size end
paths(folders, type_selection)
click to toggle source
# File lib/serum/rails/code_scanner.rb, line 24 def paths(folders, type_selection) patterns = [] folders.each do |folder| type_selection.extensions.each do |extension| patterns << "#{@root}/#{folder}/**/*.#{extension}" end end # puts "Calling patterns: #{patterns}" Dir[*patterns] end