Sha256: 1a124be1f5046a1e09bc3b06b75c3f575b24e619e99b96b85ffda6eb0ce33fc0

Contents?: true

Size: 1 KB

Versions: 2

Compression:

Stored size: 1 KB

Contents

module Trufflepig
  class Search
    attr_accessor :results, :path

    EXCLUDED_FILENAMES = /jquery|prototype|yui|dojo|extjs|raphael|zepto|enyo|ember/

    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.5 lib/trufflepig/search.rb
trufflepig-0.2.4 lib/trufflepig/search.rb