From 44901ca9039dcf512a706b06c77e11004e661666 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Tue, 31 Jan 2017 01:15:07 -0500 Subject: Raise in the initialize not in the execute --- .../lib/active_support/evented_file_update_checker.rb | 10 +++++----- activesupport/lib/active_support/file_update_checker.rb | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/evented_file_update_checker.rb b/activesupport/lib/active_support/evented_file_update_checker.rb index 080111d799..8e0dc71dca 100644 --- a/activesupport/lib/active_support/evented_file_update_checker.rb +++ b/activesupport/lib/active_support/evented_file_update_checker.rb @@ -32,6 +32,10 @@ module ActiveSupport # class EventedFileUpdateChecker #:nodoc: all def initialize(files, dirs = {}, &block) + unless block + raise ArgumentError, "A block is required to initialize an EventedFileUpdateChecker" + end + @ph = PathHelper.new @files = files.map { |f| @ph.xpath(f) }.to_set @@ -74,11 +78,7 @@ module ActiveSupport def execute @updated.make_false - if @block.nil? - raise ArgumentError, "no block given: #{self.inspect}, please pass a block when you initialize #{self.class}" - else - @block.call - end + @block.call end def execute_if_updated diff --git a/activesupport/lib/active_support/file_update_checker.rb b/activesupport/lib/active_support/file_update_checker.rb index 1af18541e3..2b5e3c1350 100644 --- a/activesupport/lib/active_support/file_update_checker.rb +++ b/activesupport/lib/active_support/file_update_checker.rb @@ -38,6 +38,10 @@ module ActiveSupport # changes. The array of files and list of directories cannot be changed # after FileUpdateChecker has been initialized. def initialize(files, dirs = {}, &block) + unless block + raise ArgumentError, "A block is required to initialize a FileUpdateChecker" + end + @files = files.freeze @glob = compile_glob(dirs) @block = block @@ -74,11 +78,7 @@ module ActiveSupport def execute @last_watched = watched @last_update_at = updated_at(@last_watched) - if @block.nil? - raise ArgumentError, "no block given: #{self.inspect}, please pass a block when you initialize #{self.class}" - else - @block.call - end + @block.call ensure @watched = nil @updated_at = nil -- cgit v1.2.3