Sha256: 1fcb3efaebc13be622cdc99f5e399577f693bf1e77cfd2285324aabfba4fb67e

Contents?: true

Size: 1.07 KB

Versions: 2

Compression:

Stored size: 1.07 KB

Contents

module Trufflepig
  class Search
    attr_accessor :results, :path

    EXCLUDED_FILENAMES = /#{%w{
      jquery prototype yui dojo extjs raphael zepto enyo ember modernizr
      bootstrap foundation
    }.join('|')}/

    def initialize(path)
      @results = []
      @path = path
    end

    def perform
      if File.directory?(path)
        Dir.chdir path
        files = {
          :html => Dir.glob(File.join("**", "*.html")),
          :js => Dir.glob(File.join("**", "*.js")),
          :css => Dir.glob(File.join("**", "*.css"))
        }
        files.each do |type, paths|
          paths.each  do |path|
            scan path unless path.split('/').last.match EXCLUDED_FILENAMES
          end
        end
      else
        scan path
      end
    end

    def scan(file_path)
      content = File.read file_path

      features.each do |feature|
        next unless feature["detection_pattern"]
        results << feature if content.match(/#{feature["detection_pattern"]}/)
      end
    end

    private

    def features
      @features ||= FeatureList.load
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
trufflepig-0.2.7 lib/trufflepig/search.rb
trufflepig-0.2.6 lib/trufflepig/search.rb