File: configuration.rb

package info (click to toggle)
ruby-sprockets 4.2.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,960 kB
  • sloc: ruby: 13,012; javascript: 157; makefile: 4
file content (79 lines) | stat: -rw-r--r-- 2,215 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# frozen_string_literal: true
require 'sprockets/compressing'
require 'sprockets/dependencies'
require 'sprockets/mime'
require 'sprockets/paths'
require 'sprockets/processing'
require 'sprockets/exporting'
require 'sprockets/transformers'
require 'sprockets/utils'

module Sprockets
  module Configuration
    include Paths, Mime, Transformers, Processing, Exporting, Compressing, Dependencies, Utils

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

    attr_reader :config

    def config=(config)
      raise TypeError, "can't assign mutable config" unless config.frozen?
      @config = config
    end

    # Get and set `Logger` instance.
    attr_accessor :logger

    # 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.
    def version
      config[:version]
    end

    # Assign an environment version.
    #
    #     environment.version = '2.0'
    #
    def version=(version)
      self.config = hash_reassoc(config, :version) { version.dup }
    end

    # Public: Returns a `Digest` implementation class.
    #
    # Defaults to `Digest::SHA256`.
    def digest_class
      config[:digest_class]
    end

    # Deprecated: Assign a `Digest` implementation class. This maybe any Ruby
    # `Digest::` implementation such as `Digest::SHA256` or
    # `Digest::SHA512`.
    #
    #     environment.digest_class = Digest::SHA512
    #
    def digest_class=(klass)
      self.config = config.merge(digest_class: klass).freeze
    end

    # This class maybe mutated and mixed in with custom helpers.
    #
    #     environment.context_class.instance_eval do
    #       include MyHelpers
    #       def asset_url; end
    #     end
    #
    attr_reader :context_class
  end
end