Class: Listen::Record::Entry

Inherits:
Object
  • Object
show all
Defined in:
lib/listen/record/entry.rb

Overview

Represents a directory entry (dir or file)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root, relative, name = nil) ⇒ Entry

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


10
11
12
13
14
# File 'lib/listen/record/entry.rb', line 10

def initialize(root, relative, name = nil)
  @root = root
  @relative = relative
  @name = name
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name


16
17
18
# File 'lib/listen/record/entry.rb', line 16

def name
  @name
end

#relativeObject (readonly)

Returns the value of attribute relative


16
17
18
# File 'lib/listen/record/entry.rb', line 16

def relative
  @relative
end

#rootObject (readonly)

Returns the value of attribute root


16
17
18
# File 'lib/listen/record/entry.rb', line 16

def root
  @root
end

Instance Method Details

#childrenObject


18
19
20
21
22
23
# 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

#metaObject


25
26
27
28
# 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_pathObject


43
44
45
# File 'lib/listen/record/entry.rb', line 43

def real_path
  @real_path ||= ::File.realpath(sys_path)
end

#record_dir_keyObject

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


34
35
36
# File 'lib/listen/record/entry.rb', line 34

def record_dir_key
  ::File.join(*[@relative, @name].compact)
end

#sys_pathObject


38
39
40
41
# 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