Class: Synchrotron::Scanner

Inherits:
Object
  • Object
show all
Defined in:
lib/synchrotron/scanner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root) ⇒ Scanner

Returns a new instance of Scanner.



6
7
8
9
# File 'lib/synchrotron/scanner.rb', line 6

def initialize(root)
  @paths = {}
  @root  = File.expand_path(root)
end

Instance Attribute Details

#pathsObject (readonly)

Returns the value of attribute paths.



4
5
6
# File 'lib/synchrotron/scanner.rb', line 4

def paths
  @paths
end

#rootObject (readonly)

Returns the value of attribute root.



4
5
6
# File 'lib/synchrotron/scanner.rb', line 4

def root
  @root
end

Instance Method Details

#scan(path = @root) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/synchrotron/scanner.rb', line 11

def scan(path = @root)
  changed = {}
  ignored = []

  Find.find(path) do |p|
    if Synchrotron.ignore.match(p)
      ignored << p
      Find.prune
    end

    old  = @paths[p]
    stat = File.lstat(p)

    changed[p] = stat if old.nil? || stat.ino != old.ino ||
        stat.mtime != old.mtime || stat.size != old.size
  end

  @paths.merge!(changed) unless changed.empty?
  {:changed => changed.values.sort, :ignored => ignored}
end