require 'find' module Pluginscan # Responsible for searching through a directory for php files, and counting the total files class FileFinder def initialize(directory) @directory = directory end def count found_files.count end def php_files found_files.php_files end private def found_files @found_files ||= find_files end def find_files found_files = FoundFiles.new Find.find @directory do |file| found_files.count += 1 unless Dir.exist?(file) # Skip directories found_files.php_files << file if file =~ /\.php$/ end found_files end FoundFiles = Struct.new(:php_files, :count) do def initialize self.php_files = [] self.count = 0 end end end end