Class: Sass::Plugin::StalenessChecker

### Home Classes Methods

### In Files

- lib/sass/plugin/staleness_checker.rb

### Parent

Object

### Methods

- ::new
- ::stylesheet_modified_since?
- ::stylesheet_needs_update?
- #stylesheet_modified_since?
- #stylesheet_needs_update?

### Class/Module Index

Quicksearch

- Sass
- Sass::CSS
- Sass::CacheStores
- Sass::CacheStores::Base
- Sass::CacheStores::Chain
- Sass::CacheStores::Filesystem
- Sass::CacheStores::Memory
- Sass::CacheStores::Null
- Sass::Callbacks
- Sass::Callbacks::InstanceMethods
- Sass::Engine
- Sass::Engine::Line
- Sass::Environment
- Sass::Exec
- Sass::Exec::Generic
- Sass::Exec::Sass
- Sass::Exec::SassConvert
- Sass::Exec::Scss
- Sass::Importers
- Sass::Importers::Base
- Sass::Importers::Filesystem
- Sass::Logger
- Sass::Logger::Base
- Sass::Logger::LogLevel
- Sass::Logger::LogLevel::ClassMethods
- Sass::Media
- Sass::Media::Query
- Sass::Media::QueryList
- Sass::Plugin
- Sass::Plugin::Compiler
- Sass::Plugin::Configuration
- Sass::Plugin::MerbBootLoader
- Sass::Plugin::Rack
- Sass::Plugin::StalenessChecker
- Sass::Repl
- Sass::SCSS
- Sass::SCSS::CssParser
- Sass::SCSS::Parser
- Sass::SCSS::RX
- Sass::SCSS::ScriptLexer
- Sass::SCSS::ScriptParser
- Sass::SCSS::StaticParser
- Sass::Script
- Sass::Script::ArgList
- Sass::Script::Bool
- Sass::Script::Color
- Sass::Script::CssLexer
- Sass::Script::CssParser
- Sass::Script::Funcall
- Sass::Script::Functions
- Sass::Script::Functions::EvaluationContext
- Sass::Script::Interpolation
- Sass::Script::Lexer
- Sass::Script::List
- Sass::Script::Literal
- Sass::Script::Node
- Sass::Script::Null
- Sass::Script::Number
- Sass::Script::Operation
- Sass::Script::Parser
- Sass::Script::String
- Sass::Script::StringInterpolation
- Sass::Script::UnaryOperation
- Sass::Script::Variable
- Sass::Selector
- Sass::Selector::AbstractSequence
- Sass::Selector::Attribute
- Sass::Selector::Class
- Sass::Selector::CommaSequence
- Sass::Selector::Element
- Sass::Selector::Id
- Sass::Selector::Interpolation
- Sass::Selector::Parent
- Sass::Selector::Placeholder
- Sass::Selector::Pseudo
- Sass::Selector::SelectorPseudoClass
- Sass::Selector::Sequence
- Sass::Selector::Simple
- Sass::Selector::SimpleSequence
- Sass::Selector::Universal
- Sass::Shared
- Sass::Supports
- Sass::Supports::Condition
- Sass::Supports::Declaration
- Sass::Supports::Interpolation
- Sass::Supports::Negation
- Sass::Supports::Operator
- Sass::SyntaxError
- Sass::Tree
- Sass::Tree::CharsetNode
- Sass::Tree::CommentNode
- Sass::Tree::ContentNode
- Sass::Tree::CssImportNode
- Sass::Tree::DebugNode
- Sass::Tree::DirectiveNode
- Sass::Tree::EachNode
- Sass::Tree::ExtendNode
- Sass::Tree::ForNode
- Sass::Tree::FunctionNode
- Sass::Tree::IfNode
- Sass::Tree::ImportNode
- Sass::Tree::MediaNode
- Sass::Tree::MixinDefNode
- Sass::Tree::MixinNode
- Sass::Tree::Node
- Sass::Tree::PropNode
- Sass::Tree::ReturnNode
- Sass::Tree::RootNode
- Sass::Tree::RuleNode
- Sass::Tree::SupportsNode
- Sass::Tree::TraceNode
- Sass::Tree::VariableNode
- Sass::Tree::Visitors
- Sass::Tree::Visitors::Base
- Sass::Tree::Visitors::CheckNesting
- Sass::Tree::Visitors::Convert
- Sass::Tree::Visitors::Cssize
- Sass::Tree::Visitors::DeepCopy
- Sass::Tree::Visitors::Extend
- Sass::Tree::Visitors::Perform
- Sass::Tree::Visitors::SetOptions
- Sass::Tree::Visitors::ToCss
- Sass::Tree::WarnNode
- Sass::Tree::WhileNode
- Sass::UnitConversionError
- Sass::Util
- Sass::Util::MultibyteStringScanner
- Sass::Util::StaticConditionalContext
- Sass::Util::SubsetMap
- Sass::Util::Test
- Sass::Version
- ActionController
- ActionController::Base
- Object

No matching classes.

# Sass::Plugin::StalenessChecker

The class handles `.sss` file staleness checks via their mtime timestamps.

To speed things up two level of caches are employed:

- A class-level dependency cache which stores @import paths for each file. This is a long-lived cache that is reused by every StalenessChecker instance.

- Three short-lived instance-level caches, one for file mtimes, one for whether a file is stale during this particular run. and one for the parse tree for a file. These are only used by a single StalenessChecker instance.

Usage:

- For a one-off staleness check of a single `.sss` file, the class-level {stylesheet_needs_update?} method should be used.

- For a series of staleness checks (e.g. checking all files for staleness) a StalenessChecker instance should be created, and the instance-level {#stylesheet_needs_update?} method should be used. the caches should make the whole process significantly faster. WARNING: It is important not to retain the instance for too long, as its instance-level caches are never explicitly expired.

### Attributes

dependencies_cache[RW]

TODO: attach this to a compiler instance. @private

### Public Class Methods

new(options) click to toggle source

Creates a new StalenessChecker for checking the staleness of several stylesheets at once.

@param options [{Symbol => Object}]

    See {file:SASS_REFERENCE.md#sass_options the Sass options documentation}.

    # File lib/sass/plugin/staleness_checker.rb, line 39
    def initialize(options)
      @dependencies = self.class.dependencies_cache

      # URIs that are being actively checked for staleness. Protects against
      # import loops.
      @actively_checking = Set.new

      # Entries in the following instance-level caches are never explicitly expired.
      # Instead they are supposed to automaticaly go out of scope when a series of staleness checks
      # (this instance of StalenessChecker was created for) is finished.
      @mtimes, @dependencies_stale, @parse_trees = {}, {}, {}
      @options = Sass::Engine.normalize_options(options)
    end

stylesheet_modified_since?(template_file, mtime, importer = nil) click to toggle source

Returns whether a Sass or SCSS stylesheet has been modified since a given time.

The distinction between this method and the instance-level {#stylesheet_modified_since?} is that the instance method preserves mtime and stale-dependency caches, so it's better to use when checking multiple stylesheets at once.

@param template_file [String] The location of the Sass or SCSS template. @param mtime [Fixnum] The modification time to check against. @param importer [Sass::Importers::Base] The importer used to locate the stylesheet.

    Defaults to the filesystem importer.

@return [Boolean] Whether the stylesheet has been modified.

    # File lib/sass/plugin/staleness_checker.rb, line 108
    def self.stylesheet_modified_since?(template_file, mtime, importer = nil)
      new(Plugin.engine_options).stylesheet_modified_since?(template_file, mtime, importer)
    end

stylesheet_needs_update?(css_file, template_file, importer = nil) click to toggle source

Returns whether or not a given CSS file is out of date and needs to be regenerated.

The distinction between this method and the instance-level {#stylesheet_needs_update?} is that the instance method preserves mtime and stale-dependency caches, so it's better to use when checking multiple stylesheets at once.

@param css_file [String] The location of the CSS file to check. @param template_file [String] The location of the Sass or SCSS template

    that is compiled to `css_file`.

@return [Boolean] Whether the stylesheet needs to be updated.

    # File lib/sass/plugin/staleness_checker.rb, line 93
    def self.stylesheet_needs_update?(css_file, template_file, importer = nil)
      new(Plugin.engine_options).stylesheet_needs_update?(css_file, template_file, importer)
    end

### Public Instance Methods

stylesheet_modified_since?(template_file, mtime, importer = nil) click to toggle source

Returns whether a Sass or SCSS stylesheet has been modified since a given time.

@param template_file [String] The location of the Sass or SCSS template. @param mtime [Fixnum] The modification time to check against. @param importer [Sass::Importers::Base] The importer used to locate the stylesheet.

    Defaults to the filesystem importer.

@return [Boolean] Whether the stylesheet has been modified.

    # File lib/sass/plugin/staleness_checker.rb, line 77
    def stylesheet_modified_since?(template_file, mtime, importer = nil)
      importer ||= @options[:filesystem_importer].new(".")
      dependency_updated?(mtime).call(template_file, importer)
    end

stylesheet_needs_update?(css_file, template_file, importer = nil) click to toggle source

Returns whether or not a given CSS file is out of date and needs to be regenerated.

@param css_file [String] The location of the CSS file to check. @param template_file [String] The location of the Sass or SCSS template

    that is compiled to `css_file`.

@return [Boolean] Whether the stylesheet needs to be updated.

    # File lib/sass/plugin/staleness_checker.rb, line 60
    def stylesheet_needs_update?(css_file, template_file, importer = nil)
      template_file = File.expand_path(template_file)
      begin
        css_mtime = File.mtime(css_file)
      rescue Errno::ENOENT
        return true
      end
      stylesheet_modified_since?(template_file, css_mtime, importer)
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.