Class: Sprockets::Base

Inherits:
Object
  • Object
show all
Includes:
Bower, Configuration, DigestUtils, HTTPUtils, Legacy, Loader, PathDigestUtils, PathUtils, Resolve, Server, URIUtils
Defined in:
lib/sprockets/base.rb

Overview

`Base` class for `Environment` and `Cached`.

Direct Known Subclasses

CachedEnvironment, Environment

Constant Summary

Constants included from Bower

Sprockets::Bower::POSSIBLE_BOWER_JSONS

Constants included from DigestUtils

DigestUtils::DIGEST_SIZES, DigestUtils::NI_HASH_ALGORITHMS

Constants included from Utils

Utils::UNBOUND_METHODS_BIND_TO_ANY_OBJECT

Constants included from PathUtils

PathUtils::SEPARATOR_PATTERN

Instance Attribute Summary collapse

Attributes included from Configuration

#config, #context_class, #logger

Instance Method Summary collapse

Methods included from Legacy

#cache_get, #cache_set, #each_logical_path, #logical_paths

Methods included from Bower

#read_bower_main, #resolve_alternates

Methods included from Resolve

#locate, #resolve

Methods included from URIUtils

#build_asset_uri, #parse_asset_uri, #valid_asset_uri?

Methods included from Loader

#load

Methods included from DigestUtils

#detect_digest_class, #digest, #digest_class, #integrity_uri, #pack_base64digest, #pack_hexdigest, #pack_urlsafe_base64digest

Methods included from Engines

#engine_mime_types, #engines, #register_engine, #unwrap_engines

Methods included from Utils

#concat_javascript_sources, #dfs, #duplicable?, #hash_reassoc, #hash_reassoc1, #module_include, #normalize_extension, #string_end_with_semicolon?

Methods included from Mime

#encodings, #mime_exts, #mime_type_charset_detecter, #mime_types, #read_file, #register_encoding, #register_mime_type

Methods included from HTTPUtils

#find_best_mime_type_match, #find_best_q_match, #find_mime_type_matches, #find_q_matches, #match_mime_type?, #parse_q_values

Methods included from PathUtils

#absolute_path?, #atomic_write, #entries, #file?, #find_upwards, #path_extnames, #path_parents, #paths_split, #relative_path?, #split_subpath, #stat, #stat_directory, #stat_sorted_tree, #stat_tree

Methods included from Processing

#bundle_processors, #bundle_reducers, #postprocessors, #preprocessors, #process_bundle_reducers, #register_bundle_metadata_reducer, #register_bundle_processor, #register_postprocessor, #register_preprocessor, #unregister_bundle_processor, #unregister_postprocessor, #unregister_preprocessor, #unwrap_bundle_processors, #unwrap_bundle_reducers, #unwrap_postprocessors, #unwrap_preprocessors

Methods included from Transformers

#expand_transform_accepts, #inverted_transformers, #register_transformer, #resolve_transform_type, #transformers, #unwrap_transformer

Methods included from Server

#call

Methods included from Configuration

#digest_class, #digest_class=, #initialize_configuration, #version, #version=

Methods included from Paths

#append_path, #clear_paths, #each_file, #paths, #prepend_path, #root

Methods included from Compressing

#compressors, #css_compressor, #css_compressor=, #js_compressor, #js_compressor=, #register_compressor

Methods included from PathDigestUtils

#files_digest, #stat_digest

Instance Attribute Details

#cacheObject

Get persistent cache store



27
28
29
# File 'lib/sprockets/base.rb', line 27

def cache
  @cache
end

Instance Method Details

#[](*args) ⇒ Object

Preferred `find_asset` shorthand.

environment['application.js']


90
91
92
# File 'lib/sprockets/base.rb', line 90

def [](*args)
  find_asset(*args)
end

#cachedObject Also known as: index

Return an `Cached`. Must be implemented by the subclass.



39
40
41
# File 'lib/sprockets/base.rb', line 39

def cached
  raise NotImplementedError
end

#file_digest(path) ⇒ Object

Internal: Compute digest for path.

path - String filename or directory path.

Returns a String digest or nil.



49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/sprockets/base.rb', line 49

def file_digest(path)
  if stat = self.stat(path)
    # Caveat: Digests are cached by the path's current mtime. Its possible
    # for a files contents to have changed and its mtime to have been
    # negligently reset thus appearing as if the file hasn't changed on
    # disk. Also, the mtime is only read to the nearest second. Its
    # also possible the file was updated more than once in a given second.
    cache.fetch(['file_digest', path, stat.mtime.to_i]) do
      self.stat_digest(path, stat)
    end
  end
end

#find_all_linked_assets(path, options = {}) {|asset| ... } ⇒ Object

Yields:

  • (asset)


69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/sprockets/base.rb', line 69

def find_all_linked_assets(path, options = {})
  return to_enum(__method__, path, options) unless block_given?

  asset = find_asset(path, options)
  return unless asset

  yield asset
  stack = asset.links.to_a

  while uri = stack.shift
    yield asset = load(uri)
    stack = asset.links.to_a + stack
  end

  nil
end

#find_asset(path, options = {}) ⇒ Object

Find asset by logical path or expanded path.



63
64
65
66
67
# File 'lib/sprockets/base.rb', line 63

def find_asset(path, options = {})
  if uri = locate(path, options)
    load(uri)
  end
end

#inspectObject

Pretty inspect



95
96
97
98
99
# File 'lib/sprockets/base.rb', line 95

def inspect
  "#<#{self.class}:0x#{object_id.to_s(16)} " +
    "root=#{root.to_s.inspect}, " +
    "paths=#{paths.inspect}>"
end