Class: Sprockets::BundledAsset

### Home Classes Methods

### In Files

- lib/sprockets/bundled_asset.rb

### Parent

Sprockets::Asset

### Methods

- ::new
- #body
- #dependencies
- #encode_with
- #fresh?
- #init_with
- #to_a

### 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::ClosureCompressor
- Sprockets::Compressing
- 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::NotImplementedError
- Sprockets::Paths
- Sprockets::ProcessedAsset
- Sprockets::ProcessedAsset::DependencyFile
- Sprockets::Processing
- Sprockets::Processor
- Sprockets::SafetyColons
- Sprockets::SassCacheStore
- Sprockets::SassCompressor
- Sprockets::SassFunctions
- Sprockets::SassImporter
- Sprockets::SassTemplate
- Sprockets::ScssTemplate
- Sprockets::Server
- Sprockets::StaticAsset
- Sprockets::UglifierCompressor
- Sprockets::UnserializeError
- Sprockets::Utils
- Sprockets::YUICompressor
- Rake
- Rake::SprocketsTask

No matching classes.

# Sprockets::BundledAsset

`BundledAsset`s are used for files that need to be processed and concatenated with other assets. Use for `.js` and `.css` files.

### Attributes

source[R]

### Public Class Methods

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

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

      @processed_asset  = environment.find_asset(pathname, :bundle => false)
      @required_assets  = @processed_asset.required_assets
      @dependency_paths = @processed_asset.dependency_paths

      # Explode Asset into parts and gather the dependency bodies
      @source = to_a.map { |dependency| dependency.to_s }.join

      # Run bundle processors on concatenated source
      context = environment.context_class.new(environment, logical_path, pathname)
      @source = context.evaluate(pathname, :data => @source,
                  :processors => environment.bundle_processors(content_type))

      @mtime  = (to_a + @dependency_paths).map(&:mtime).max
      @length = Rack::Utils.bytesize(source)
      @digest = environment.digest.update(source).hexdigest
    end

### Public Instance Methods

body() click to toggle source

Get asset's own processed contents. Excludes any of its required dependencies but does run any processors or engines on the original file.

    # File lib/sprockets/bundled_asset.rb, line 58
    def body
      @processed_asset.source
    end

dependencies() click to toggle source

Return an `Array` of `Asset` files that are declared dependencies.

    # File lib/sprockets/bundled_asset.rb, line 63
    def dependencies
      to_a.reject { |a| a.eql?(@processed_asset) }
    end

encode_with(coder) click to toggle source

Serialize custom attributes in `BundledAsset`.

    # File lib/sprockets/bundled_asset.rb, line 48
    def encode_with(coder)
      super

      coder['source'] = source
      coder['required_assets_digest'] = @processed_asset.dependency_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/bundled_asset.rb, line 74
    def fresh?(environment)
      @processed_asset.fresh?(environment)
    end

init_with(environment, coder) click to toggle source

Initialize `BundledAsset` from serialized `Hash`.

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

      @processed_asset = environment.find_asset(pathname, :bundle => false)
      @required_assets = @processed_asset.required_assets

      if @processed_asset.dependency_digest != coder['required_assets_digest']
        raise UnserializeError, "processed asset belongs to a stale environment"
      end

      @source = coder['source']
    end

to_a() click to toggle source

Expand asset into an `Array` of parts.

    # File lib/sprockets/bundled_asset.rb, line 68
    def to_a
      required_assets
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.