Class: SassListen::Record

Inherits:
Object
  • Object
show all
Defined in:
lib/sass-listen/record/entry.rb,
lib/sass-listen/record.rb,
lib/sass-listen/record/symlink_detector.rb

Defined Under Namespace

Classes: Entry, SymlinkDetector

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(directory) ⇒ Record

Returns a new instance of Record.


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

def initialize(directory)
  @tree = _auto_hash
  @root = directory.to_s
end

Instance Attribute Details

#rootObject (readonly)

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


10
11
12
# File 'lib/sass-listen/record.rb', line 10

def root
  @root
end

Instance Method Details

#add_dir(rel_path) ⇒ Object


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

def add_dir(rel_path)
  return if [nil, '', '.'].include? rel_path
  @tree[rel_path] ||= {}
end

#buildObject


60
61
62
63
64
65
66
67
68
69
# File 'lib/sass-listen/record.rb', line 60

def build
  @tree = _auto_hash
  # 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


43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/sass-listen/record.rb', line 43

def dir_entries(rel_path)
  subtree =
    if [nil, '', '.'].include? rel_path.to_s
      tree
    else
      tree[rel_path.to_s] ||= _auto_hash
      tree[rel_path.to_s]
    end

  result = {}
  subtree.each do |key, values|
    # only get data for file entries
    result[key] = values.key?(:mtime) ? values : {}
  end
  result
end

#file_data(rel_path) ⇒ Object


31
32
33
34
35
36
37
38
39
40
41
# File 'lib/sass-listen/record.rb', line 31

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

#unset_path(rel_path) ⇒ Object


26
27
28
29
# File 'lib/sass-listen/record.rb', line 26

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


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

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