Sha256: 694657d5a09621124f730d965b8e0c770ba76b0c8861eb5e4925c5c7eee7c4be
Contents?: true
Size: 1.93 KB
Versions: 14
Compression:
Stored size: 1.93 KB
Contents
class PeakFlowUtils::ErbInspector def initialize(args = {}) @args = args @args[:exts] ||= [".erb", ".haml", ".liquid", ".markerb", ".rb", ".rake", ".slim", "."] + PeakFlowUtils::ErbInspector::FileInspector::JS_FILE_EXTS if @args[:dirs] @dirs = @args[:dirs] else @dirs = PeakFlowUtils::ConfigurationService.current.paths_to_translate end end # Yields all relevant .erb- and .haml-files. def files Enumerator.new do |yielder| @dirs.each do |dir| scan_dir("", dir, yielder) end end end def file(root_path, file_path) PeakFlowUtils::ErbInspector::FileInspector.new( file_path: file_path, root_path: root_path ) end private def scan_dir(path, root_path, yielder) Dir.foreach("#{root_path}/#{path}") do |file| next if file == "." || file == ".." file_path = path.clone file_path << "/" unless file_path.empty? file_path << file file_path_with_path = "#{path}/#{file_path}" full_path = "#{root_path}/#{file_path}" ext = File.extname(file_path) if File.directory?(full_path) scan_dir(file_path, root_path, yielder) elsif @args[:exts].include?(ext) scanned_file = PeakFlowUtils::ScannedFile.find_or_initialize_by(file_path: file_path_with_path) file_size = File.size(full_path) last_changed_at = File.mtime(full_path) changed = false changed = true unless file_size == scanned_file.file_size changed = true unless last_changed_at.to_s == scanned_file.last_changed_at.to_s if changed scanned_file.assign_attributes( file_size: file_size, last_changed_at: last_changed_at ) scanned_file.save! end yielder << PeakFlowUtils::ErbInspector::FileInspector.new( file_path: file_path, root_path: root_path, changed: changed ) end end end end
Version data entries
14 entries across 14 versions & 1 rubygems