diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2017-01-31 01:15:07 -0500 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2017-01-31 01:15:07 -0500 |
commit | 44901ca9039dcf512a706b06c77e11004e661666 (patch) | |
tree | 39b40ecac2bd4c9d176252e3f7ff7dba3453afbb /activesupport/lib | |
parent | 6d8fdd136b0e922be5bb6cc103ffdb244d73248e (diff) | |
download | rails-44901ca9039dcf512a706b06c77e11004e661666.tar.gz rails-44901ca9039dcf512a706b06c77e11004e661666.tar.bz2 rails-44901ca9039dcf512a706b06c77e11004e661666.zip |
Raise in the initialize not in the execute
Diffstat (limited to 'activesupport/lib')
-rw-r--r-- | activesupport/lib/active_support/evented_file_update_checker.rb | 10 | ||||
-rw-r--r-- | activesupport/lib/active_support/file_update_checker.rb | 10 |
2 files changed, 10 insertions, 10 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 |