diff options
3 files changed, 12 insertions, 13 deletions
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 diff --git a/activesupport/test/file_update_checker_shared_tests.rb b/activesupport/test/file_update_checker_shared_tests.rb index de8796bf06..d038b4debd 100644 --- a/activesupport/test/file_update_checker_shared_tests.rb +++ b/activesupport/test/file_update_checker_shared_tests.rb @@ -274,10 +274,9 @@ module FileUpdateCheckerSharedTests assert_equal 2, i end - test "execute raises an ArgumentError if no block given" do - checker = new_checker([]) + test "initialize raises an ArgumentError if no block given" do assert_raise ArgumentError do - checker.execute + checker = new_checker([]) end end end |