aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2017-01-31 01:15:07 -0500
committerRafael Mendonça França <rafaelmfranca@gmail.com>2017-01-31 01:15:07 -0500
commit44901ca9039dcf512a706b06c77e11004e661666 (patch)
tree39b40ecac2bd4c9d176252e3f7ff7dba3453afbb
parent6d8fdd136b0e922be5bb6cc103ffdb244d73248e (diff)
downloadrails-44901ca9039dcf512a706b06c77e11004e661666.tar.gz
rails-44901ca9039dcf512a706b06c77e11004e661666.tar.bz2
rails-44901ca9039dcf512a706b06c77e11004e661666.zip
Raise in the initialize not in the execute
-rw-r--r--activesupport/lib/active_support/evented_file_update_checker.rb10
-rw-r--r--activesupport/lib/active_support/file_update_checker.rb10
-rw-r--r--activesupport/test/file_update_checker_shared_tests.rb5
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