Class: FSEvents::Event

Inherits:
Object
  • Object
show all
Defined in:
lib/fsevents/event.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, path, stream) ⇒ Event

Returns a new instance of Event.



5
6
7
8
9
# File 'lib/fsevents/event.rb', line 5

def initialize(id, path, stream)
  @id     = id
  @path   = path.sub(%r%/$%, '')
  @stream = stream
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



3
4
5
# File 'lib/fsevents/event.rb', line 3

def id
  @id
end

#pathObject (readonly)

Returns the value of attribute path.



3
4
5
# File 'lib/fsevents/event.rb', line 3

def path
  @path
end

#streamObject (readonly)

Returns the value of attribute stream.



3
4
5
# File 'lib/fsevents/event.rb', line 3

def stream
  @stream
end

Instance Method Details

#deleted_filesObject



33
34
35
36
37
38
39
40
41
42
# File 'lib/fsevents/event.rb', line 33

def deleted_files
  case stream.mode
  when :mtime
    raise RuntimeError, 'This mode does not support getting deleted files'
  when :cache
    cache = stream.dirs[path] || {}
    
    cache.keys - files
  end
end

#filesObject



11
12
13
# File 'lib/fsevents/event.rb', line 11

def files
  Dir["#{path}/*"]
end

#modified_filesObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/fsevents/event.rb', line 15

def modified_files
  case stream.mode
  when :mtime
    files.select { |f|  File.mtime(f) >= stream.last_event }
  when :cache
    cache = stream.dirs[path] || {}
    
    files.select do |f|
      cached = cache[f]
      
      cached.nil? or
      
      File.mtime(f) != cached.mtime or
      File.size(f)  != cached.size
    end
  end
end