# File lib/sprockets/processed_asset.rb, line 6 6: def initialize(environment, logical_path, pathname) 7: super 8: 9: start_time = Time.now.to_f 10: 11: context = environment.context_class.new(environment, logical_path, pathname) 12: @source = context.evaluate(pathname) 13: @length = Rack::Utils.bytesize(source) 14: @digest = environment.digest.update(source).hexdigest 15: 16: build_required_assets(environment, context) 17: build_dependency_paths(environment, context) 18: 19: @dependency_digest = compute_dependency_digest(environment) 20: 21: elapsed_time = ((Time.now.to_f - start_time) * 1000).to_i 22: environment.logger.info "Compiled #{logical_path} (#{elapsed_time}ms) (pid #{Process.pid})" 23: end
Serialize custom attributes in `BundledAsset`.
# File lib/sprockets/processed_asset.rb, line 52 52: def encode_with(coder) 53: super 54: 55: coder['source'] = source 56: coder['dependency_digest'] = dependency_digest 57: 58: coder['required_paths'] = required_assets.map { |a| 59: relativize_root_path(a.pathname).to_s 60: } 61: coder['dependency_paths'] = dependency_paths.map { |d| 62: { 'path' => relativize_root_path(d.pathname).to_s, 63: 'mtime' => d.mtime.iso8601, 64: 'digest' => d.digest } 65: } 66: end
Checks if Asset is stale by comparing the actual mtime and digest to the inmemory model.
# File lib/sprockets/processed_asset.rb, line 70 70: def fresh?(environment) 71: # Check freshness of all declared dependencies 72: @dependency_paths.all? { |dep| dependency_fresh?(environment, dep) } 73: end
Initialize `BundledAsset` from serialized `Hash`.
# File lib/sprockets/processed_asset.rb, line 31 31: def init_with(environment, coder) 32: super 33: 34: @source = coder['source'] 35: @dependency_digest = coder['dependency_digest'] 36: 37: @required_assets = coder['required_paths'].map { |p| 38: p = expand_root_path(p) 39: 40: unless environment.paths.detect { |path| p[path] } 41: raise UnserializeError, "#{p} isn't in paths" 42: end 43: 44: p == pathname.to_s ? self : environment.find_asset(p, :bundle => false) 45: } 46: @dependency_paths = coder['dependency_paths'].map { |h| 47: DependencyFile.new(expand_root_path(h['path']), h['mtime'], h['digest']) 48: } 49: end
# File lib/sprockets/processed_asset.rb, line 124 124: def build_dependency_paths(environment, context) 125: dependency_paths = {} 126: 127: context._dependency_paths.each do |path| 128: dep = DependencyFile.new(path, environment.stat(path).mtime, environment.file_digest(path).hexdigest) 129: dependency_paths[dep] = true 130: end 131: 132: context._dependency_assets.each do |path| 133: if path == self.pathname.to_s 134: dep = DependencyFile.new(pathname, environment.stat(path).mtime, environment.file_digest(path).hexdigest) 135: dependency_paths[dep] = true 136: elsif asset = environment.find_asset(path, :bundle => false) 137: asset.dependency_paths.each do |d| 138: dependency_paths[d] = true 139: end 140: end 141: end 142: 143: @dependency_paths = dependency_paths.keys 144: end
# File lib/sprockets/processed_asset.rb, line 96 96: def build_required_assets(environment, context) 97: @required_assets = resolve_dependencies(environment, context._required_paths + [pathname.to_s]) - 98: resolve_dependencies(environment, context._stubbed_assets.to_a) 99: end
# File lib/sprockets/processed_asset.rb, line 146 146: def compute_dependency_digest(environment) 147: required_assets.inject(environment.digest) { |digest, asset| 148: digest.update asset.digest 149: }.hexdigest 150: end
# File lib/sprockets/processed_asset.rb, line 101 101: def resolve_dependencies(environment, paths) 102: assets = [] 103: cache = {} 104: 105: paths.each do |path| 106: if path == self.pathname.to_s 107: unless cache[self] 108: cache[self] = true 109: assets << self 110: end 111: elsif asset = environment.find_asset(path, :bundle => false) 112: asset.required_assets.each do |asset_dependency| 113: unless cache[asset_dependency] 114: cache[asset_dependency] = true 115: assets << asset_dependency 116: end 117: end 118: end 119: end 120: 121: assets 122: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.