Class: Sprockets::Bundle

### Home Classes Methods

### In Files

- lib/sprockets/bundle.rb

### Parent

Object

### Methods

- ::call
- ::process_bundle_reducers

### Class/Module Index

Quicksearch

- Sprockets
- Sprockets::ArgumentError
- Sprockets::Asset
- Sprockets::Autoload
- Sprockets::Base
- Sprockets::Bower
- Sprockets::Bundle
- Sprockets::Cache
- Sprockets::Cache::FileStore
- Sprockets::Cache::GetWrapper
- Sprockets::Cache::HashWrapper
- Sprockets::Cache::MemoryStore
- Sprockets::Cache::NullStore
- Sprockets::Cache::ReadWriteWrapper
- Sprockets::Cache::Wrapper
- Sprockets::CachedEnvironment
- Sprockets::ClosureCompressor
- Sprockets::CoffeeScriptProcessor
- Sprockets::CoffeeScriptTemplate
- Sprockets::Compressing
- Sprockets::Configuration
- Sprockets::ContentTypeMismatch
- Sprockets::Context
- Sprockets::ConversionError
- Sprockets::Dependencies
- Sprockets::DigestUtils
- Sprockets::DirectiveProcessor
- Sprockets::ERBProcessor
- Sprockets::ERBTemplate
- Sprockets::EcoProcessor
- Sprockets::EcoTemplate
- Sprockets::EjsProcessor
- Sprockets::EjsTemplate
- Sprockets::EncodingUtils
- Sprockets::Engines
- Sprockets::Environment
- Sprockets::Error
- Sprockets::FileNotFound
- Sprockets::FileOutsidePaths
- Sprockets::FileReader
- Sprockets::HTTPUtils
- Sprockets::Index
- Sprockets::JstProcessor
- Sprockets::LegacyProcProcessor
- Sprockets::LegacyTiltProcessor
- Sprockets::Loader
- Sprockets::Manifest
- Sprockets::ManifestUtils
- Sprockets::Mime
- Sprockets::NotFound
- Sprockets::NotImplementedError
- Sprockets::PathDependencyUtils
- Sprockets::PathDigestUtils
- Sprockets::PathUtils
- Sprockets::Paths
- Sprockets::Processing
- Sprockets::ProcessorUtils
- Sprockets::Resolve
- Sprockets::SassCompressor
- Sprockets::SassProcessor
- Sprockets::SassProcessor::CacheStore
- Sprockets::SassProcessor::Functions
- Sprockets::SassTemplate
- Sprockets::ScssProcessor
- Sprockets::ScssTemplate
- Sprockets::Server
- Sprockets::Transformers
- Sprockets::URITar
- Sprockets::URIUtils
- Sprockets::UglifierCompressor
- Sprockets::UnloadedAsset
- Sprockets::Utils
- Sprockets::YUICompressor
- Rake
- Rake::SprocketsTask

No matching classes.

# Sprockets::Bundle

Internal: Bundle processor takes a single file asset and prepends all the `:required` URIs to the contents.

Uses pipeline metadata:

    :required - Ordered Set of asset URIs to prepend
    :stubbed  - Set of asset URIs to substract from the required set.

Also see DirectiveProcessor.

### Public Class Methods

call(input) click to toggle source

    # File lib/sprockets/bundle.rb, line 15
    def self.call(input)
      env  = input[:environment]
      type = input[:content_type]
      dependencies = Set.new(input[:metadata][:dependencies])

      processed_uri, deps = env.resolve(input[:filename], accept: type, pipeline: :self, compat: false)
      dependencies.merge(deps)

      find_required = proc { |uri| env.load(uri).metadata[:required] }
      required = Utils.dfs(processed_uri, &find_required)
      stubbed  = Utils.dfs(env.load(processed_uri).metadata[:stubbed], &find_required)
      required.subtract(stubbed)
      assets = required.map { |uri| env.load(uri) }

      (required + stubbed).each do |uri|
        dependencies.merge(env.load(uri).metadata[:dependencies])
      end

      reducers = Hash[env.match_mime_type_keys(env.config[:bundle_reducers], type).flat_map(&:to_a)]
      process_bundle_reducers(assets, reducers).merge(dependencies: dependencies, included: assets.map(&:uri))
    end

process_bundle_reducers(assets, reducers) click to toggle source

Internal: Run bundle reducers on set of Assets producing a reduced metadata Hash.

assets - Array of Assets reducers - Array of [initial, reducer_proc] pairs

Returns reduced asset metadata Hash.

    # File lib/sprockets/bundle.rb, line 44
    def self.process_bundle_reducers(assets, reducers)
      initial = {}
      reducers.each do |k, (v, _)|
        if v.respond_to?(:call)
          initial[k] = v.call
        elsif !v.nil?
          initial[k] = v
        end
      end

      assets.reduce(initial) do |h, asset|
        reducers.each do |k, (_, block)|
          value = k == :data ? asset.source : asset.metadata[k]
          if h.key?(k)
            if !value.nil?
              h[k] = block.call(h[k], value)
            end
          else
            h[k] = value
          end
        end
        h
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.