Class: Sass::Plugin::StalenessChecker
- Inherits:
-
Object
- Object
- Sass::Plugin::StalenessChecker
- Defined in:
- .ruby-sass/lib/sass/plugin/staleness_checker.rb
Overview
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 StalenessChecker.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.
Class Attribute Summary (collapse)
-
.dependencies_cache ⇒ Object
TODO: attach this to a compiler instance.
-
.dependency_cache_mutex ⇒ Object
readonly
Returns the value of attribute dependency_cache_mutex.
Class Method Summary (collapse)
-
.stylesheet_modified_since?(template_file, mtime, importer = nil) ⇒ Boolean
Returns whether a Sass or SCSS stylesheet has been modified since a given time.
-
.stylesheet_needs_update?(css_file, template_file, importer = nil) ⇒ Boolean
Returns whether or not a given CSS file is out of date and needs to be regenerated.
Instance Method Summary (collapse)
-
#initialize(options) ⇒ StalenessChecker
constructor
Creates a new StalenessChecker for checking the staleness of several stylesheets at once.
-
#stylesheet_modified_since?(template_file, mtime, importer = nil) ⇒ Boolean
Returns whether a Sass or SCSS stylesheet has been modified since a given time.
-
#stylesheet_needs_update?(css_file, template_file, importer = nil) ⇒ Boolean
Returns whether or not a given CSS file is out of date and needs to be regenerated.
Constructor Details
#initialize(options) ⇒ StalenessChecker
Creates a new StalenessChecker for checking the staleness of several stylesheets at once.
43 44 45 46 47 48 49 50 51 52 53 |
# File '.ruby-sass/lib/sass/plugin/staleness_checker.rb', line 43 def initialize() # 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.() end |
Constructor Details
#initialize(options) ⇒ StalenessChecker
Creates a new StalenessChecker for checking the staleness of several stylesheets at once.
43 44 45 46 47 48 49 50 51 52 53 |
# File '.ruby-sass/lib/sass/plugin/staleness_checker.rb', line 43 def initialize() # 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.() end |
Class Attribute Details
.dependencies_cache ⇒ Object
TODO: attach this to a compiler instance.
34 35 36 |
# File '.ruby-sass/lib/sass/plugin/staleness_checker.rb', line 34 def dependencies_cache @dependencies_cache end |
.dependency_cache_mutex ⇒ Object (readonly)
Returns the value of attribute dependency_cache_mutex
35 36 37 |
# File '.ruby-sass/lib/sass/plugin/staleness_checker.rb', line 35 def dependency_cache_mutex @dependency_cache_mutex end |
Class Method Details
.stylesheet_modified_since?(template_file, mtime, importer = nil) ⇒ Boolean
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.
110 111 112 |
# File '.ruby-sass/lib/sass/plugin/staleness_checker.rb', line 110 def self.stylesheet_modified_since?(template_file, mtime, importer = nil) new(Plugin.).stylesheet_modified_since?(template_file, mtime, importer) end |
.stylesheet_needs_update?(css_file, template_file, importer = nil) ⇒ Boolean
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.
95 96 97 |
# File '.ruby-sass/lib/sass/plugin/staleness_checker.rb', line 95 def self.stylesheet_needs_update?(css_file, template_file, importer = nil) new(Plugin.).stylesheet_needs_update?(css_file, template_file, importer) end |
Instance Method Details
#stylesheet_modified_since?(template_file, mtime, importer = nil) ⇒ Boolean
Returns whether a Sass or SCSS stylesheet has been modified since a given time.
79 80 81 82 |
# File '.ruby-sass/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) ⇒ Boolean
Returns whether or not a given CSS file is out of date and needs to be regenerated.
62 63 64 65 66 67 68 69 70 |
# File '.ruby-sass/lib/sass/plugin/staleness_checker.rb', line 62 def stylesheet_needs_update?(css_file, template_file, importer = nil) template_file = File.(template_file) begin css_mtime = File.mtime(css_file) rescue Errno::ENOENT return true end stylesheet_modified_since?(template_file, css_mtime, importer) end |