Module: Sprockets::Dependencies
- Includes:
- DigestUtils, PathDigestUtils, URIUtils
- Included in:
- Configuration
- Defined in:
- lib/sprockets/dependencies.rb
Overview
‘Dependencies` is an internal mixin whose public methods are exposed on the `Environment` and `CachedEnvironment` classes.
Constant Summary
Constants included from DigestUtils
Sprockets::DigestUtils::DIGEST_SIZES, Sprockets::DigestUtils::NI_HASH_ALGORITHMS
Constants included from PathUtils
Instance Method Summary collapse
-
#add_dependency(uri) ⇒ Object
(also: #depend_on)
Public: Add environmental dependency inheirted by all assets.
-
#dependencies ⇒ Object
Public: Default set of dependency URIs for assets.
-
#dependency_resolvers ⇒ Object
Public: Mapping dependency schemes to resolver functions.
-
#register_dependency_resolver(scheme, &block) ⇒ Object
Public: Register new dependency URI resolver.
-
#resolve_dependencies(uris) ⇒ Object
Internal: Resolve set of dependency URIs.
-
#resolve_dependency(str) ⇒ Object
Internal: Resolve dependency URIs.
Methods included from DigestUtils
#detect_digest_class, #digest, #digest_class, #integrity_uri, #pack_base64digest, #pack_hexdigest, #pack_urlsafe_base64digest
Methods included from PathDigestUtils
#file_digest, #files_digest, #stat_digest
Methods included from PathUtils
#absolute_path?, #atomic_write, #directory?, #entries, #file?, #find_upwards, #match_path_extname, #path_extnames, #path_parents, #paths_split, #relative_path?, #split_subpath, #stat, #stat_directory, #stat_sorted_tree, #stat_tree
Methods included from URIUtils
#build_asset_uri, #build_file_digest_uri, #encode_uri_query_params, #join_file_uri, #join_uri, #parse_asset_uri, #parse_file_digest_uri, #parse_uri_query_params, #split_file_uri, #split_uri, #valid_asset_uri?
Instance Method Details
#add_dependency(uri) ⇒ Object Also known as: depend_on
Public: Add environmental dependency inheirted by all assets.
uri - String dependency URI
Returns nothing.
47 48 49 50 51 |
# File 'lib/sprockets/dependencies.rb', line 47 def add_dependency(uri) self.config = hash_reassoc(config, :dependencies) do |set| set + Set.new([uri]) end end |
#dependencies ⇒ Object
Public: Default set of dependency URIs for assets.
Returns Set of String URIs.
24 25 26 |
# File 'lib/sprockets/dependencies.rb', line 24 def dependencies config[:dependencies] end |
#dependency_resolvers ⇒ Object
Public: Mapping dependency schemes to resolver functions.
key - String scheme value - Proc.call(Environment, String)
Returns Hash.
17 18 19 |
# File 'lib/sprockets/dependencies.rb', line 17 def dependency_resolvers config[:dependency_resolvers] end |
#register_dependency_resolver(scheme, &block) ⇒ Object
Public: Register new dependency URI resolver.
scheme - String scheme block -
environment - Environment
uri - String dependency URI
Returns nothing.
36 37 38 39 40 |
# File 'lib/sprockets/dependencies.rb', line 36 def register_dependency_resolver(scheme, &block) self.config = hash_reassoc(config, :dependency_resolvers) do |hash| hash.merge(scheme => block) end end |
#resolve_dependencies(uris) ⇒ Object
Internal: Resolve set of dependency URIs.
Returns Array of resolved Objects.
57 58 59 |
# File 'lib/sprockets/dependencies.rb', line 57 def resolve_dependencies(uris) uris.map { |uri| resolve_dependency(uri) } end |
#resolve_dependency(str) ⇒ Object
Internal: Resolve dependency URIs.
Returns resolved Object.
64 65 66 67 68 69 70 71 |
# File 'lib/sprockets/dependencies.rb', line 64 def resolve_dependency(str) scheme = str[/([^:]+)/, 1] if resolver = config[:dependency_resolvers][scheme] resolver.call(self, str) else nil end end |