Class: Listen::Record

Inherits:
Object show all
Defined in:
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/listen-3.8.0/lib/listen/record/entry.rb,
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/listen-3.8.0/lib/listen/record.rb,
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/listen-3.8.0/lib/listen/record/symlink_detector.rb

Defined Under Namespace

Classes: Entry, SymlinkDetector

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(directory, silencer) ⇒ Record

Returns a new instance of Record.



14
15
16
17
18
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/listen-3.8.0/lib/listen/record.rb', line 14

def initialize(directory, silencer)
  reset_tree
  @root = directory.to_s
  @silencer = silencer
end

Instance Attribute Details

#rootObject (readonly)

TODO: one Record object per watched directory? TODO: deprecate



12
13
14
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/listen-3.8.0/lib/listen/record.rb', line 12

def root
  @root
end

Instance Method Details

#add_dir(rel_path) ⇒ Object



20
21
22
23
24
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/listen-3.8.0/lib/listen/record.rb', line 20

def add_dir(rel_path)
  if !empty_dirname?(rel_path.to_s)
    @tree[rel_path.to_s]
  end
end

#buildObject



62
63
64
65
66
67
68
69
70
71
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/listen-3.8.0/lib/listen/record.rb', line 62

def build
  reset_tree
  # TODO: test with a file name given
  # TODO: test other permissions
  # TODO: test with mixed encoding
  symlink_detector = SymlinkDetector.new
  remaining = ::Queue.new
  remaining << Entry.new(root, nil, nil)
  _fast_build_dir(remaining, symlink_detector) until remaining.empty?
end

#dir_entries(rel_path) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/listen-3.8.0/lib/listen/record.rb', line 46

def dir_entries(rel_path)
  rel_path_s = rel_path.to_s
  subtree = if empty_dirname?(rel_path_s)
    @tree
  else
    @tree[rel_path_s]
  end

  subtree.each_with_object({}) do |(key, values), result|
    # only return data for file entries inside the dir (which will each be sub-hashes)
    if values.is_a?(Hash)
      result[key] = values.has_key?(:mtime) ? values : {}
    end
  end
end

#file_data(rel_path) ⇒ Object



36
37
38
39
40
41
42
43
44
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/listen-3.8.0/lib/listen/record.rb', line 36

def file_data(rel_path)
  dirname, basename = Pathname(rel_path).split.map(&:to_s)
  if empty_dirname?(dirname)
    @tree[basename].dup
  else
    @tree[dirname][basename] ||= {}
    @tree[dirname][basename].dup
  end
end

#unset_path(rel_path) ⇒ Object



31
32
33
34
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/listen-3.8.0/lib/listen/record.rb', line 31

def unset_path(rel_path)
  dirname, basename = Pathname(rel_path).split.map(&:to_s)
  _fast_unset_path(dirname, basename)
end

#update_file(rel_path, data) ⇒ Object



26
27
28
29
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/listen-3.8.0/lib/listen/record.rb', line 26

def update_file(rel_path, data)
  dirname, basename = Pathname(rel_path).split.map(&:to_s)
  _fast_update_file(dirname, basename, data)
end