Class: Listen::Record

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(listener) ⇒ Record

Returns a new instance of Record.



8
9
10
11
# File 'lib/listen/record.rb', line 8

def initialize(listener)
  @listener = listener
  @paths    = _init_paths
end

Instance Attribute Details

#listenerObject

TODO: deprecate



6
7
8
# File 'lib/listen/record.rb', line 6

def listener
  @listener
end

#pathsObject

TODO: deprecate



6
7
8
# File 'lib/listen/record.rb', line 6

def paths
  @paths
end

Instance Method Details

#_init_pathsObject (private)



49
50
51
# File 'lib/listen/record.rb', line 49

def _init_paths
  Hash.new { |h, k| h[k] = Hash.new }
end

#buildObject



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

def build
  @last_build_at = Time.now
  @paths = _init_paths
  listener.directories.each do |path|
    options = { recursive: true, silence: true, build: true }
    listener.sync(:change_pool).change(:dir, path, options)
  end
  sleep 0.01 until @last_build_at + 0.1 < Time.now
rescue
  Celluloid.logger.warn "build crashed: #{$!.inspect}"
  raise
end

#dir_entries(path) ⇒ Object



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

def dir_entries(path)
  @paths[path.to_s].dup
end

#file_data(path) ⇒ Object



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

def file_data(path)
  @paths[::File.dirname(path)][::File.basename(path)] || {}
end

#set_path(type, path, data = {}) ⇒ Object



13
14
15
16
# File 'lib/listen/record.rb', line 13

def set_path(type, path, data = {})
  new_data = file_data(path).merge(data).merge(type: type)
  @paths[::File.dirname(path)][::File.basename(path)] = new_data
end

#still_building!Object



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

def still_building!
  @last_build_at = Time.now
end

#unset_path(path) ⇒ Object



18
19
20
# File 'lib/listen/record.rb', line 18

def unset_path(path)
  @paths[::File.dirname(path)].delete(::File.basename(path))
end