Class: RuntimeFileReader

Inherits:
Object
  • Object
show all
Defined in:
lib/gorgon/runtime_file_reader.rb

Instance Method Summary collapse

Constructor Details

#initialize(configuration) ⇒ RuntimeFileReader

Returns a new instance of RuntimeFileReader.



5
6
7
8
# File 'lib/gorgon/runtime_file_reader.rb', line 5

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

Instance Method Details

#old_filesObject



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/gorgon/runtime_file_reader.rb', line 10

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

#sorted_filesObject

sorts by 1.) globs, 2.) runtime



22
23
24
25
26
# File 'lib/gorgon/runtime_file_reader.rb', line 22

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