Class: Sprockets::ProcessedAsset

### Home Classes Methods

### In Files

- lib/sprockets/processed_asset.rb

### Parent

Sprockets::Asset

### Namespace

- CLASS Sprockets::ProcessedAsset::DependencyFile

### Methods

- ::new
- #encode_with
- #fresh?
- #init_with

### Class/Module Index

Quicksearch

- Sprockets
- Sprockets::ArgumentError
- Sprockets::Asset
- Sprockets::AssetAttributes
- Sprockets::Base
- Sprockets::BundledAsset
- Sprockets::Cache
- Sprockets::Cache::FileStore
- Sprockets::Caching
- Sprockets::CharsetNormalizer
- Sprockets::CircularDependencyError
- Sprockets::ContentTypeMismatch
- Sprockets::Context
- Sprockets::DirectiveProcessor
- Sprockets::EcoTemplate
- Sprockets::EjsTemplate
- Sprockets::EncodingError
- Sprockets::EngineError
- Sprockets::Engines
- Sprockets::Environment
- Sprockets::Error
- Sprockets::FileNotFound
- Sprockets::FileOutsidePaths
- Sprockets::Index
- Sprockets::JstProcessor
- Sprockets::Manifest
- Sprockets::Mime
- Sprockets::ProcessedAsset
- Sprockets::ProcessedAsset::DependencyFile
- Sprockets::Processing
- Sprockets::Processor
- Sprockets::SafetyColons
- Sprockets::Server
- Sprockets::StaticAsset
- Sprockets::Trail
- Sprockets::UnserializeError
- Sprockets::Utils
- Rake
- Rake::SprocketsTask

No matching classes.

# Sprockets::ProcessedAsset

### Attributes

dependency_digest[R]

Interal: Used to check equality

source[R]

### Public Class Methods

new(environment, logical_path, pathname) click to toggle source

    # File lib/sprockets/processed_asset.rb, line 6
    def initialize(environment, logical_path, pathname)
      super

      start_time = Time.now.to_f

      context = environment.context_class.new(environment, logical_path, pathname)
      @source = context.evaluate(pathname)
      @length = Rack::Utils.bytesize(source)
      @digest = environment.digest.update(source).hexdigest

      build_required_assets(environment, context)
      build_dependency_paths(environment, context)

      @dependency_digest = compute_dependency_digest(environment)

      elapsed_time = ((Time.now.to_f - start_time) * 1000).to_i
      environment.logger.info "Compiled #{logical_path}  (#{elapsed_time}ms)  (pid #{Process.pid})"
    end

### Public Instance Methods

encode_with(coder) click to toggle source

Serialize custom attributes in `BundledAsset`.

    # File lib/sprockets/processed_asset.rb, line 52
    def encode_with(coder)
      super

      coder['source'] = source
      coder['dependency_digest'] = dependency_digest

      coder['required_paths'] = required_assets.map { |a|
        relativize_root_path(a.pathname).to_s
      }
      coder['dependency_paths'] = dependency_paths.map { |d|
        { 'path' => relativize_root_path(d.pathname).to_s,
          'mtime' => d.mtime.iso8601,
          'digest' => d.digest }
      }
    end

fresh?(environment) click to toggle source

Checks if Asset is stale by comparing the actual mtime and digest to the inmemory model.

    # File lib/sprockets/processed_asset.rb, line 70
    def fresh?(environment)
      # Check freshness of all declared dependencies
      @dependency_paths.all? { |dep| dependency_fresh?(environment, dep) }
    end

init_with(environment, coder) click to toggle source

Initialize `BundledAsset` from serialized `Hash`.

    # File lib/sprockets/processed_asset.rb, line 31
    def init_with(environment, coder)
      super

      @source = coder['source']
      @dependency_digest = coder['dependency_digest']

      @required_assets = coder['required_paths'].map { |p|
        p = expand_root_path(p)

        unless environment.paths.detect { |path| p[path] }
          raise UnserializeError, "#{p} isn't in paths"
        end

        p == pathname.to_s ? self : environment.find_asset(p, :bundle => false)
      }
      @dependency_paths = coder['dependency_paths'].map { |h|
        DependencyFile.new(expand_root_path(h['path']), h['mtime'], h['digest'])
      }
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.