Class: Sprockets::Environment

### Home Classes Methods

### In Files

- lib/sprockets/environment.rb

### Parent

Sprockets::Base

### Methods

- ::new
- #expire_index!
- #find_asset
- #index

### 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::Environment

### Public Class Methods

new(root = ".") click to toggle source

`Environment` should initialized with your application's root directory. This should be the same as your Rails or Rack root.

    env = Environment.new(Rails.root)

    # File lib/sprockets/environment.rb, line 20
    def initialize(root = ".")
      @trail = Hike::Trail.new(root)

      self.logger = Logger.new($stderr)
      self.logger.level = Logger::FATAL

      if respond_to?(:default_external_encoding)
        self.default_external_encoding = Encoding::UTF_8
      end

      # Create a safe `Context` subclass to mutate
      @context_class = Class.new(Context)

      # Set MD5 as the default digest
      require 'digest/md5'
      @digest_class = ::Digest::MD5
      @version = ''

      @mime_types        = {}
      @engines           = Sprockets.engines
      @preprocessors     = Hash.new { |h, k| h[k] = [] }
      @postprocessors    = Hash.new { |h, k| h[k] = [] }
      @bundle_processors = Hash.new { |h, k| h[k] = [] }

      @engines.each do |ext, klass|
        add_engine_to_trail(ext, klass)
      end

      register_mime_type 'text/css', '.css'
      register_mime_type 'application/javascript', '.js'

      register_preprocessor 'text/css', DirectiveProcessor
      register_preprocessor 'application/javascript', DirectiveProcessor

      register_postprocessor 'application/javascript', SafetyColons
      register_bundle_processor 'text/css', CharsetNormalizer

      expire_index!

      yield self if block_given?
    end

### Public Instance Methods

find_asset(path, options = {}) click to toggle source

Cache `find_asset` calls

    # File lib/sprockets/environment.rb, line 72
    def find_asset(path, options = {})
      options[:bundle] = true unless options.key?(:bundle)

      # Ensure inmemory cached assets are still fresh on every lookup
      if (asset = @assets[cache_key_for(path, options)]) && asset.fresh?(self)
        asset
      elsif asset = index.find_asset(path, options)
        # Cache is pushed upstream by Index#find_asset
        asset
      end
    end

index() click to toggle source

Returns a cached version of the environment.

All its file system calls are cached which makes `index` much faster. This behavior is ideal in production since the file system only changes between deploys.

    # File lib/sprockets/environment.rb, line 67
    def index
      Index.new(self)
    end

### Protected Instance Methods

expire_index!() click to toggle source

    # File lib/sprockets/environment.rb, line 85
    def expire_index!
      # Clear digest to be recomputed
      @digest = nil
      @assets = {}
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.