class Listen::Record::Entry

Represents a directory entry (dir or file)

Attributes

name[R]
relative[R]
root[R]

Public Class Methods

new(root, relative, name = nil) click to toggle source

file: “/home/me/watched_dir”, “app/models”, “foo.rb” dir, “/home/me/watched_dir”, “.”

# File lib/listen/record/entry.rb, line 10
def initialize(root, relative, name = nil)
  @root = root
  @relative = relative
  @name = name
end

Public Instance Methods

children() click to toggle source
# File lib/listen/record/entry.rb, line 18
def children
  child_relative = _join
  (_entries(sys_path) - %w[. ..]).map do |name|
    Entry.new(@root, child_relative, name)
  end
end
meta() click to toggle source
# File lib/listen/record/entry.rb, line 25
def meta
  lstat = ::File.lstat(sys_path)
  { mtime: lstat.mtime.to_f, mode: lstat.mode, size: lstat.size }
end
real_path() click to toggle source
# File lib/listen/record/entry.rb, line 43
def real_path
  @real_path ||= ::File.realpath(sys_path)
end
record_dir_key() click to toggle source

record hash is e.g. if @record[“project/app/models”] if @record[“project/app”] record_dir_key is “project/app/models”

# File lib/listen/record/entry.rb, line 34
def record_dir_key
  ::File.join(*[@relative, @name].compact)
end
sys_path() click to toggle source
# File lib/listen/record/entry.rb, line 38
def sys_path
  # Use full path in case someone uses chdir
  ::File.join(*[@root, @relative, @name].compact)
end

Private Instance Methods

_entries(dir) click to toggle source
# File lib/listen/record/entry.rb, line 54
def _entries(dir)
  return Dir.entries(dir) unless RUBY_ENGINE == 'jruby'

  # JRuby inconsistency workaround, see:
  # https://github.com/jruby/jruby/issues/3840
  exists = ::File.exist?(dir)
  directory = ::File.directory?(dir)
  return Dir.entries(dir) unless exists && !directory
  raise Errno::ENOTDIR, dir
end
_join() click to toggle source
# File lib/listen/record/entry.rb, line 49
def _join
  args = [@relative, @name].compact
  args.empty? ? nil : ::File.join(*args)
end