Parent

Included Modules

Listen::Record

Attributes

listener[RW]

TODO: deprecate

paths[RW]

TODO: deprecate

Public Class Methods

new(listener) click to toggle source
# File lib/listen/record.rb, line 10
def initialize(listener)
  @listener = listener
  @paths    = _auto_hash
end

Public Instance Methods

add_dir(dir, rel_path) click to toggle source
# File lib/listen/record.rb, line 15
def add_dir(dir, rel_path)
  return if [nil, '', '.'].include? rel_path
  @paths[dir.to_s][rel_path] ||= {}
end
build() click to toggle source
# File lib/listen/record.rb, line 59
def build
  start = Time.now.to_f
  @paths = _auto_hash

  # TODO: refactor this out (1 Record = 1 watched dir)
  listener.directories.each do |directory|
    _fast_build(directory.to_s)
  end

  Celluloid.logger.info "Record.build took #{Time.now.to_f - start} seconds"
rescue
  Celluloid.logger.warn "build crashed: #{$!.inspect}"
  raise
end
dir_entries(dir, rel_path) click to toggle source
# File lib/listen/record.rb, line 43
def dir_entries(dir, rel_path)
  tree = if [nil, '', '.'].include? rel_path.to_s
           @paths[dir.to_s]
         else
           @paths[dir.to_s][rel_path.to_s] ||= _auto_hash
           @paths[dir.to_s][rel_path.to_s]
         end

  result = {}
  tree.each do |key, values|
    # only get data for file entries
    result[key] = values.key?(:mtime) ? values : {}
  end
  result
end
file_data(dir, rel_path) click to toggle source
# File lib/listen/record.rb, line 30
def file_data(dir, rel_path)
  root = @paths[dir.to_s]
  dirname, basename = Pathname(rel_path).split.map(&:to_s)
  if [nil, '', '.'].include? dirname
    root[basename] ||= {}
    root[basename].dup
  else
    root[dirname] ||= {}
    root[dirname][basename] ||= {}
    root[dirname][basename].dup
  end
end
unset_path(dir, rel_path) click to toggle source
# File lib/listen/record.rb, line 25
def unset_path(dir, rel_path)
  dirname, basename = Pathname(rel_path).split.map(&:to_s)
  _fast_unset_path(dir, dirname, basename)
end
update_file(dir, rel_path, data) click to toggle source
# File lib/listen/record.rb, line 20
def update_file(dir, rel_path, data)
  dirname, basename = Pathname(rel_path).split.map(&:to_s)
  _fast_update_file(dir, dirname, basename, data)
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.