Method: Listen::QueueOptimizer#_squash_changes

Defined in:
lib/listen/queue_optimizer.rb

#_squash_changes(changes) ⇒ Object (private)

groups changes into the expected structure expected by clients



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/listen/queue_optimizer.rb', line 23

def _squash_changes(changes)
  # We combine here for backward compatibility
  # Newer clients should receive dir and path separately
  changes = changes.map { |change, dir, path| [change, dir + path] }

  actions = changes.group_by(&:last).map do |path, action_list|
    [_logical_action_for(path, action_list.map(&:first)), path.to_s]
  end
  _log :info, "listen: raw changes: #{actions.inspect}"

  { modified: [], added: [], removed: [] }.tap do |squashed|
    actions.each do |type, path|
      squashed[type] << path unless type.nil?
    end
    _log :info, "listen: final changes: #{squashed.inspect}"
  end
end