Class: SassListen::Record::Entry

Inherits:
Object
  • Object
show all
Defined in:
lib/sass-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”, “.”


8
9
10
# File 'lib/sass-listen/record/entry.rb', line 8

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

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name


12
13
14
# File 'lib/sass-listen/record/entry.rb', line 12

def name
  @name
end

#relativeObject (readonly)

Returns the value of attribute relative


12
13
14
# File 'lib/sass-listen/record/entry.rb', line 12

def relative
  @relative
end

#rootObject (readonly)

Returns the value of attribute root


12
13
14
# File 'lib/sass-listen/record/entry.rb', line 12

def root
  @root
end

Instance Method Details

#childrenObject


14
15
16
17
18
19
# File 'lib/sass-listen/record/entry.rb', line 14

def children
  child_relative = _join
  (_entries(sys_path) - %w(. ..)).map do |name|
    Entry.new(@root, child_relative, name)
  end
end

#metaObject


21
22
23
24
# File 'lib/sass-listen/record/entry.rb', line 21

def meta
  lstat = ::File.lstat(sys_path)
  { mtime: lstat.mtime.to_f, mode: lstat.mode }
end

#real_pathObject


39
40
41
# File 'lib/sass-listen/record/entry.rb', line 39

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”


30
31
32
# File 'lib/sass-listen/record/entry.rb', line 30

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

#sys_pathObject


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

def sys_path
  # Use full path in case someone uses chdir
  ::File.join(*[@root, @relative, @name].compact)
end