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::HASH_ALGORITHMS

Constants included from PathUtils

PathUtils::SEPARATOR_PATTERN

Instance Method Summary collapse

Methods included from DigestUtils

#detect_digest_class, #digest, #digest_class, #hexdigest, #hexdigest_integrity_uri, #integrity_uri, #pack_base64digest, #pack_hexdigest, #pack_urlsafe_base64digest, #unpack_hexdigest

Methods included from PathDigestUtils

#file_digest, #files_digest, #stat_digest

Methods included from PathUtils

#absolute_path?, #atomic_write, #directory?, #entries, #file?, #find_matching_path_for_extensions, #find_upwards, #join, #match_path_extname, #path_extnames, #path_parents, #paths_split, #relative_path?, #relative_path_from, #set_pipeline, #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.



48
49
50
51
52
# File 'lib/sprockets/dependencies.rb', line 48

def add_dependency(uri)
  self.config = hash_reassoc(config, :dependencies) do |set|
    set + Set.new([uri])
  end
end

#dependenciesObject

Public: Default set of dependency URIs for assets.

Returns Set of String URIs.



25
26
27
# File 'lib/sprockets/dependencies.rb', line 25

def dependencies
  config[:dependencies]
end

#dependency_resolversObject

Public: Mapping dependency schemes to resolver functions.

key - String scheme value - Proc.call(Environment, String)

Returns Hash.



18
19
20
# File 'lib/sprockets/dependencies.rb', line 18

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.



37
38
39
40
41
# File 'lib/sprockets/dependencies.rb', line 37

def register_dependency_resolver(scheme, &block)
  self.config = hash_reassoc(config, :dependency_resolvers) do |hash|
    hash.merge(scheme => block)
  end
end

#resolve_dependency(str) ⇒ Object

Internal: Resolve dependency URIs.

Returns resolved Object.



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/sprockets/dependencies.rb', line 58

def resolve_dependency(str)
  # Optimize for the most common scheme to
  # save 22k allocations on an average Spree app.
  scheme = if str.start_with?('file-digest:'.freeze)
    'file-digest'.freeze
  else
    str[/([^:]+)/, 1]
  end

  if resolver = config[:dependency_resolvers][scheme]
    resolver.call(self, str)
  else
    nil
  end
end