class Hanami::Assets::Cache

Store assets references when compile mode is on.

This is especially useful in development mode, where we want to compile only the assets that were changed from last browser refresh.

@since 0.1.0 @api private

Public Class Methods

new() click to toggle source

Return a new instance

@return [Hanami::Assets::Cache] a new instance

# File lib/hanami/assets/cache.rb, line 68
def initialize
  @data  = Hash.new { |h, k| h[k] = File.new(k, mtime: 0) }
  @mutex = Mutex.new
end

Public Instance Methods

modified?(file) click to toggle source

Check if the given file was modified

@param file [String,Pathname] the file path

@return [TrueClass,FalseClass] the result of the check

@since 0.3.0 @api private

# File lib/hanami/assets/cache.rb, line 81
def modified?(file)
  @mutex.synchronize do
    @data[file.to_s].modified?(file)
  end
end
store(file, dependencies = nil) click to toggle source

Store the given file reference

@param file [String,Pathname] the file path

@return [TrueClass,FalseClass] the result of the check

@since 0.1.0 @api private

# File lib/hanami/assets/cache.rb, line 95
def store(file, dependencies = nil)
  @mutex.synchronize do
    @data[file.to_s] = File.new(file, dependencies: dependencies)
  end
end