### 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::BaseEnvironment
- 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::Base
- Sass::Exec::SassConvert
- Sass::Exec::SassScss
- Sass::Exec::SassScss::Sass::Plugin.compiler
- Sass::Features
- 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::ReadOnlyEnvironment
- 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::CssLexer
- Sass::Script::CssParser
- Sass::Script::Functions
- Sass::Script::Functions::EvaluationContext
- Sass::Script::Lexer
- Sass::Script::Parser
- Sass::Script::Tree
- Sass::Script::Tree::Funcall
- Sass::Script::Tree::Interpolation
- Sass::Script::Tree::ListLiteral
- Sass::Script::Tree::Literal
- Sass::Script::Tree::MapLiteral
- Sass::Script::Tree::Node
- Sass::Script::Tree::Operation
- Sass::Script::Tree::Selector
- Sass::Script::Tree::StringInterpolation
- Sass::Script::Tree::UnaryOperation
- Sass::Script::Tree::Variable
- Sass::Script::Value
- Sass::Script::Value::ArgList
- Sass::Script::Value::Base
- Sass::Script::Value::Bool
- Sass::Script::Value::Color
- Sass::Script::Value::Helpers
- Sass::Script::Value::List
- Sass::Script::Value::Map
- Sass::Script::Value::Null
- Sass::Script::Value::Number
- Sass::Script::Value::String
- Sass::Selector
- Sass::Selector::AbstractSequence
- Sass::Selector::Attribute
- Sass::Selector::Class
- Sass::Selector::CommaSequence
- Sass::Selector::Element
- Sass::Selector::Id
- Sass::Selector::Parent
- Sass::Selector::Placeholder
- Sass::Selector::Pseudo
- Sass::Selector::Sequence
- Sass::Selector::Simple
- Sass::Selector::SimpleSequence
- Sass::Selector::Universal
- Sass::SemiGlobalEnvironment
- Sass::Shared
- Sass::Source
- Sass::Source::Map
- Sass::Source::Map::Mapping
- Sass::Source::Position
- Sass::Source::Range
- Sass::Stack
- Sass::Stack::Frame
- Sass::Supports
- Sass::Supports::Condition
- Sass::Supports::Declaration
- Sass::Supports::Interpolation
- Sass::Supports::Negation
- Sass::Supports::Operator
- Sass::SyntaxError
- Sass::Tree
- Sass::Tree::AtRootNode
- Sass::Tree::CharsetNode
- Sass::Tree::CommentNode
- Sass::Tree::ContentNode
- Sass::Tree::CssImportNode
- Sass::Tree::DebugNode
- Sass::Tree::DirectiveNode
- Sass::Tree::EachNode
- Sass::Tree::ErrorNode
- Sass::Tree::ExtendNode
- Sass::Tree::ForNode
- Sass::Tree::FunctionNode
- Sass::Tree::IfNode
- Sass::Tree::ImportNode
- Sass::Tree::KeyframeRuleNode
- 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::Cssize::Bubble
- 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::CrossPlatformRandom
- Sass::Util::MultibyteStringScanner
- Sass::Util::NormalizedMap
- Sass::Util::StaticConditionalContext
- Sass::Util::SubsetMap
- Sass::Util::Test
- Sass::Version
- ActionController
- ActionController::Base
- Object
- OrderedHash

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

dependency_cache_mutex[R]

### 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 43
    def initialize(options)
      # 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 automatically 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 110
    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 95
    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 79
    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 62
    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.