Class: Listen::Record::Entry
- Inherits:
-
Object
- Object
- Listen::Record::Entry
- Defined in:
- lib/listen/record/entry.rb
Overview
Represents a directory entry (dir or file)
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#relative ⇒ Object
readonly
Returns the value of attribute relative.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Instance Method Summary collapse
- #_entries(dir) ⇒ Object private
- #_join ⇒ Object private
- #children ⇒ Object
-
#initialize(root, relative, name = nil) ⇒ Entry
constructor
file: "/home/me/watched_dir", "app/models", "foo.rb" dir, "/home/me/watched_dir", ".".
- #meta ⇒ Object
- #real_path ⇒ Object
-
#record_dir_key ⇒ Object
record hash is e.g.
- #sys_path ⇒ Object
Constructor Details
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
16 17 18 |
# File 'lib/listen/record/entry.rb', line 16 def name @name end |
#relative ⇒ Object (readonly)
Returns the value of attribute relative.
16 17 18 |
# File 'lib/listen/record/entry.rb', line 16 def relative @relative end |
#root ⇒ Object (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
#_entries(dir) ⇒ Object (private)
54 55 56 57 58 59 60 61 62 63 |
# 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 ⇒ Object (private)
49 50 51 52 |
# File 'lib/listen/record/entry.rb', line 49 def _join args = [@relative, @name].compact args.empty? ? nil : ::File.join(*args) end |
#children ⇒ Object
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 |
#meta ⇒ Object
25 26 27 28 |
# File 'lib/listen/record/entry.rb', line 25 def lstat = ::File.lstat(sys_path) { mtime: lstat.mtime.to_f, mode: lstat.mode, size: lstat.size } end |
#real_path ⇒ Object
43 44 45 |
# File 'lib/listen/record/entry.rb', line 43 def real_path @real_path ||= ::File.realpath(sys_path) end |
#record_dir_key ⇒ Object
record hash is e.g. if @record["/home/me/watched_dir"]["project/app/models"]["foo.rb"] if @record["/home/me/watched_dir"]["project/app"]["models"] 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_path ⇒ Object
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 |