Class: ModifiedFilter

Inherits:
Object
  • Object
show all
Defined in:
lib/filters/modified_filter.rb

Instance Method Summary collapse

Constructor Details

#initialize(file_class, last_modified = nil) ⇒ ModifiedFilter

Returns a new instance of ModifiedFilter.



3
4
5
6
7
8
# File 'lib/filters/modified_filter.rb', line 3

def initialize(file_class, last_modified = nil)
  @file_class = file_class
  @last_modified = last_modified
  @modifieds = []
  @prev_file_sizes = {}
end

Instance Method Details

#completeObject



23
24
25
26
# File 'lib/filters/modified_filter.rb', line 23

def complete
  @last_modified = @modifieds.max
  @modifieds = []
end

#filter(path) ⇒ Object



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

def filter(path)
  modified = @file_class.mtime(path)
  @modifieds << modified
  
  file_size = @file_class.size(path)
  prev_file_size = @prev_file_sizes[path]
  modified = @last_modified.nil? || modified > @last_modified || prev_file_size.nil? || file_size != prev_file_size
  
  @prev_file_sizes[path] = file_size
  
  return modified
end