Sha256: 366ead3e57aa08cd5852b1d42600bfe8c30d462b30603d9a0154bd467c5e4fb6

Contents?: true

Size: 981 Bytes

Versions: 42

Compression:

Stored size: 981 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::Callbacks.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

42 entries across 42 versions & 3 rubygems

Version Path
social_url_stats-0.0.1 vendor/ruby/1.9.1/gems/activesupport-3.0.0/lib/active_support/file_update_checker.rb
activesupport-3.0.20 lib/active_support/file_update_checker.rb
activesupport-3.0.19 lib/active_support/file_update_checker.rb
activesupport-3.0.18 lib/active_support/file_update_checker.rb
activesupport-3.0.17 lib/active_support/file_update_checker.rb
activesupport-3.0.16 lib/active_support/file_update_checker.rb
activesupport-3.0.15 lib/active_support/file_update_checker.rb
activesupport-3.0.14 lib/active_support/file_update_checker.rb
activesupport-3.0.13 lib/active_support/file_update_checker.rb
activesupport-3.0.13.rc1 lib/active_support/file_update_checker.rb
activesupport-3.0.12 lib/active_support/file_update_checker.rb
activesupport-3.0.12.rc1 lib/active_support/file_update_checker.rb
activesupport-3.0.11 lib/active_support/file_update_checker.rb
messagebus_ruby_api-0.4.7 spec/ruby/1.9.1/gems/activesupport-3.0.9/lib/active_support/file_update_checker.rb
messagebus_ruby_api-0.4.4 spec/ruby/1.9.1/gems/activesupport-3.0.9/lib/active_support/file_update_checker.rb
activesupport-3.0.10 lib/active_support/file_update_checker.rb
activesupport-3.0.10.rc1 lib/active_support/file_update_checker.rb
activesupport-3.0.9 lib/active_support/file_update_checker.rb
activesupport-3.0.9.rc5 lib/active_support/file_update_checker.rb
activesupport-3.0.9.rc4 lib/active_support/file_update_checker.rb