Skip to content

Commit

Permalink
issue #504: remove more early returns
Browse files Browse the repository at this point in the history
  • Loading branch information
ColinDKelley committed Nov 24, 2020
1 parent c9a6205 commit 39a2a4c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 21 deletions.
8 changes: 4 additions & 4 deletions lib/listen/event/processor.rb
Expand Up @@ -51,10 +51,10 @@ def _wait_until_no_longer_paused
end

def _check_stopped
return unless @listener.stopped?

_flush_wakeup_reasons
raise Stopped
if @listener.stopped?
_flush_wakeup_reasons
raise Stopped
end
end

def _sleep(seconds)
Expand Down
6 changes: 1 addition & 5 deletions lib/listen/options.rb
Expand Up @@ -9,11 +9,7 @@ def initialize(opts, defaults)
@options[key] = given_options.delete(key) || defaults[key]
end

return if given_options.empty?

msg = "Unknown options: #{given_options.inspect}"
Listen.logger.warn msg
fail msg
given_options.empty? or raise ArgumentError, "Unknown options: #{given_options.inspect}"
end

# rubocop:disable Lint/MissingSuper
Expand Down
16 changes: 4 additions & 12 deletions lib/listen/queue_optimizer.rb
Expand Up @@ -91,10 +91,8 @@ def _calculate_add_remove_difference(actions, path, default_if_exists)
def _reinterpret_related_changes(cookies)
table = { moved_to: :added, moved_from: :removed }
cookies.flat_map do |_, changes|
data = _detect_possible_editor_save(changes)
if data
to_dir, to_file = data
[[:modified, to_dir, to_file]]
if (editor_modified = editor_modified?(changes))
[[:modified, *editor_modified]]
else
not_silenced = changes.reject do |type, _, _, path, _|
config.silenced?(Pathname(path), type)
Expand All @@ -106,8 +104,7 @@ def _reinterpret_related_changes(cookies)
end
end

# rubocop:disable Metrics/MethodLength
def _detect_possible_editor_save(changes)
def editor_modified?(changes)
return unless changes.size == 2

from_type = from = nil
Expand All @@ -119,19 +116,14 @@ def _detect_possible_editor_save(changes)
from_type, _from_change, _, from, = data
when :moved_to
to_type, _to_change, to_dir, to, = data
else
return nil
end
end

return unless from && to

# Expect an ignored moved_from and non-ignored moved_to
# to qualify as an "editor modify"
if config.silenced?(Pathname(from), from_type) && !config.silenced?(Pathname(to), to_type)
if from && to && config.silenced?(Pathname(from), from_type) && !config.silenced?(Pathname(to), to_type)
[to_dir, to]
end
end
# rubocop:enable Metrics/MethodLength
end
end

0 comments on commit 39a2a4c

Please sign in to comment.