Class: Gorgon::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.



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

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



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

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



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

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