Sha256: b07d900dcf4db9ea3b0b19c6fa134d7a1c3b2f94e6d8c63460dc5990b40a8db5

Contents?: true

Size: 980 Bytes

Versions: 55

Compression:

Stored size: 980 Bytes

Contents

module ActiveSupport
  # This class is responsible to track files and invoke the given block
  # whenever one of these files are changed. For example, this class
  # is used by Rails to reload the I18n framework whenever they are
  # changed upon a new request.
  #
  #   i18n_reloader = ActiveSupport::FileUpdateChecker.new(paths) do
  #     I18n.reload!
  #   end
  #
  #   ActionDispatch::Reloader.to_prepare do
  #     i18n_reloader.execute_if_updated
  #   end
  #
  class FileUpdateChecker
    attr_reader :paths, :last_update_at

    def initialize(paths, calculate=false, &block)
      @paths = paths
      @block = block
      @last_update_at = calculate ? updated_at : nil
    end

    def updated_at
      paths.map { |path| File.stat(path).mtime }.max
    end

    def execute_if_updated
      current_update_at = self.updated_at
      if @last_update_at != current_update_at
        @last_update_at = current_update_at
        @block.call
      end
    end
  end
end

Version data entries

55 entries across 55 versions & 2 rubygems

Version Path
activesupport-3.1.12 lib/active_support/file_update_checker.rb
activesupport-3.1.11 lib/active_support/file_update_checker.rb
activesupport-3.1.10 lib/active_support/file_update_checker.rb
activesupport-3.1.9 lib/active_support/file_update_checker.rb
dirty_history-0.7.3 dirty_history/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/file_update_checker.rb
dirty_history-0.7.2 dirty_history/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/file_update_checker.rb
dirty_history-0.7.1 dirty_history/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/file_update_checker.rb
dirty_history-0.7.0 dirty_history/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/file_update_checker.rb
dirty_history-0.6.7 dirty_history/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/file_update_checker.rb
dirty_history-0.6.6 dirty_history/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/file_update_checker.rb
dirty_history-0.6.5 dirty_history/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/file_update_checker.rb
dirty_history-0.6.4 dirty_history/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/file_update_checker.rb
activesupport-3.1.8 lib/active_support/file_update_checker.rb
dirty_history-0.6.3 dirty_history/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/file_update_checker.rb
activesupport-3.1.7 lib/active_support/file_update_checker.rb
dirty_history-0.6.2 dirty_history/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/file_update_checker.rb
dirty_history-0.6.1 dirty_history/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/file_update_checker.rb
dirty_history-0.6.0 dirty_history/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/file_update_checker.rb
activesupport-3.1.6 lib/active_support/file_update_checker.rb
dirty_history-0.5.4 dirty_history/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/file_update_checker.rb