Module: Sprockets::Configuration

Includes:
Compressing, Dependencies, Exporting, Mime, Paths, Processing, Transformers, Utils
Included in:
Sprockets, Base
Defined in:
lib/sprockets/configuration.rb

Constant Summary

Constants included from PathUtils

PathUtils::SEPARATOR_PATTERN

Constants included from ProcessorUtils

ProcessorUtils::VALID_METADATA_COMPOUND_TYPES, ProcessorUtils::VALID_METADATA_COMPOUND_TYPES_HASH, ProcessorUtils::VALID_METADATA_TYPES, ProcessorUtils::VALID_METADATA_VALUE_TYPES, ProcessorUtils::VALID_METADATA_VALUE_TYPES_HASH

Constants included from DigestUtils

DigestUtils::DIGEST_SIZES, DigestUtils::HASH_ALGORITHMS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Paths

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

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 Utils

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

Methods included from Mime

#mime_exts, #mime_type_charset_detecter, #mime_types, #read_file, #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?, #match_mime_type_keys, #parse_q_values

Methods included from Transformers

#compose_transformers, #expand_transform_accepts, #register_transformer, #register_transformer_suffix, #resolve_transform_type, #transformers

Methods included from ProcessorUtils

#call_processor, #call_processors, #compose_processors, #processor_cache_key, #processors_cache_keys, #validate_processor_result!

Methods included from Processing

#bundle_processors, #pipelines, #postprocessors, #preprocessors, #register_bundle_metadata_reducer, #register_bundle_processor, #register_pipeline, #register_postprocessor, #register_preprocessor, #unregister_bundle_processor, #unregister_postprocessor, #unregister_preprocessor

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?

Methods included from Exporting

#export_concurrent, #export_concurrent=, #exporters, #register_exporter, #unregister_exporter

Methods included from Compressing

#compressors, #css_compressor, #css_compressor=, #gzip=, #gzip?, #js_compressor, #js_compressor=, #register_compressor, #skip_gzip?

Methods included from Dependencies

#add_dependency, #dependencies, #dependency_resolvers, #register_dependency_resolver, #resolve_dependency

Methods included from DigestUtils

#already_digested?, #detect_digest_class, #digest, #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

Instance Attribute Details

#configObject

Returns the value of attribute config.



21
22
23
# File 'lib/sprockets/configuration.rb', line 21

def config
  @config
end

#context_classObject (readonly)

This class maybe mutated and mixed in with custom helpers.

environment.context_class.instance_eval do
  include MyHelpers
  def asset_url; end
end


77
78
79
# File 'lib/sprockets/configuration.rb', line 77

def context_class
  @context_class
end

#loggerObject

Get and set ‘Logger` instance.



29
30
31
# File 'lib/sprockets/configuration.rb', line 29

def logger
  @logger
end

Instance Method Details

#digest_classObject

Public: Returns a ‘Digest` implementation class.

Defaults to ‘Digest::SHA256`.



56
57
58
# File 'lib/sprockets/configuration.rb', line 56

def digest_class
  config[:digest_class]
end

#digest_class=(klass) ⇒ Object

Deprecated: Assign a ‘Digest` implementation class. This maybe any Ruby `Digest::` implementation such as `Digest::SHA256` or `Digest::SHA512`.

environment.digest_class = Digest::SHA512


66
67
68
# File 'lib/sprockets/configuration.rb', line 66

def digest_class=(klass)
  self.config = config.merge(digest_class: klass).freeze
end

#initialize_configuration(parent) ⇒ Object



15
16
17
18
19
# File 'lib/sprockets/configuration.rb', line 15

def initialize_configuration(parent)
  @config = parent.config
  @logger = parent.logger
  @context_class = Class.new(parent.context_class)
end

#versionObject

The ‘Environment#version` is a custom value used for manually expiring all asset caches.

Sprockets is able to track most file and directory changes and will take care of expiring the cache for you. However, its impossible to know when any custom helpers change that you mix into the ‘Context`.

It would be wise to increment this value anytime you make a configuration change to the ‘Environment` object.



41
42
43
# File 'lib/sprockets/configuration.rb', line 41

def version
  config[:version]
end

#version=(version) ⇒ Object

Assign an environment version.

environment.version = '2.0'


49
50
51
# File 'lib/sprockets/configuration.rb', line 49

def version=(version)
  self.config = hash_reassoc(config, :version) { version.dup }
end