Sha256: 1130ffbf220d8d9f47b261f255e4645a45e81b8ed3d45c1a8c4f1c56873b86eb

Contents?: true

Size: 946 Bytes

Versions: 10

Compression:

Stored size: 946 Bytes

Contents

require 'yajl'

class RuntimeFileReader

  def initialize(configuration)
    @runtime_filename = configuration[:runtime_file] || ""
    @globs_of_files = configuration[:files] || [] # e.g. ["spec/file1_spec.rb", "spec/**/*_spec.rb"]
  end

  def old_files
    @old_files ||= unless File.file?(@runtime_filename)
                     []
                   else
                     File.open(@runtime_filename, 'r') do |f|
                       parser = Yajl::Parser.new
                       hash = parser.parse(f)
                       hash.nil? ? [] : hash.keys
                     end
                   end
  end

  def sorted_files # sorts by 1.) globs, 2.) runtime
    @globs_of_files.reduce([]) do |memo, glob|
      memo.concat( sorted_files_by_runtime(Dir[glob]) )
    end.uniq
  end

  private

  def sorted_files_by_runtime(current_files = [])
    (self.old_files+current_files).uniq - (self.old_files-current_files)
  end



end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
gorgon-0.11.0 lib/gorgon/runtime_file_reader.rb
gorgon-0.10.5 lib/gorgon/runtime_file_reader.rb
gorgon-0.10.4 lib/gorgon/runtime_file_reader.rb
gorgon-0.10.3 lib/gorgon/runtime_file_reader.rb
gorgon-0.10.2 lib/gorgon/runtime_file_reader.rb
gorgon-0.10.1 lib/gorgon/runtime_file_reader.rb
gorgon-0.10.0 lib/gorgon/runtime_file_reader.rb
gorgon-0.9.0 lib/gorgon/runtime_file_reader.rb
gorgon-0.8.4 lib/gorgon/runtime_file_reader.rb
gorgon-0.8.3 lib/gorgon/runtime_file_reader.rb