Sha256: 33828e2fafbcd11737129ffd8c399a3024a3892f453aab33dc86c8f1e971479c

Contents?: true

Size: 1.99 KB

Versions: 83

Compression:

Stored size: 1.99 KB

Contents

require 'sprockets/path_utils'
require 'sprockets/utils'

module Sprockets
  module Paths
    include PathUtils, Utils

    # Returns `Environment` root.
    #
    # All relative paths are expanded with root as its base. To be
    # useful set this to your applications root directory. (`Rails.root`)
    def root
      config[:root]
    end

    # Internal: Change Environment root.
    #
    # Only the initializer should change the root.
    def root=(path)
      self.config = hash_reassoc(config, :root) do
        File.expand_path(path)
      end
    end
    private :root=

    # Returns an `Array` of path `String`s.
    #
    # These paths will be used for asset logical path lookups.
    def paths
      config[:paths]
    end

    # Prepend a `path` to the `paths` list.
    #
    # Paths at the end of the `Array` have the least priority.
    def prepend_path(path)
      self.config = hash_reassoc(config, :paths) do |paths|
        path = File.expand_path(path, config[:root]).freeze
        paths.unshift(path)
      end
    end

    # Append a `path` to the `paths` list.
    #
    # Paths at the beginning of the `Array` have a higher priority.
    def append_path(path)
      self.config = hash_reassoc(config, :paths) do |paths|
        path = File.expand_path(path, config[:root]).freeze
        paths.push(path)
      end
    end

    # Clear all paths and start fresh.
    #
    # There is no mechanism for reordering paths, so its best to
    # completely wipe the paths list and reappend them in the order
    # you want.
    def clear_paths
      self.config = hash_reassoc(config, :paths) do |paths|
        paths.clear
      end
    end

    # Public: Iterate over every file under all load paths.
    #
    # Returns Enumerator if no block is given.
    def each_file
      return to_enum(__method__) unless block_given?

      paths.each do |root|
        stat_tree(root).each do |filename, stat|
          if stat.file?
            yield filename
          end
        end
      end

      nil
    end
  end
end

Version data entries

83 entries across 77 versions & 15 rubygems

Version Path
sprockets-3.7.5 lib/sprockets/paths.rb
sprockets-3.7.4 lib/sprockets/paths.rb
sprockets-3.7.3 lib/sprockets/paths.rb
files.com-1.0.55 docs/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/paths.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/paths.rb
zuora_connect_ui-0.9.2 vendor/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/paths.rb
chatops-rpc-0.0.2 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/paths.rb
chatops-rpc-0.0.1 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/paths.rb
zuora_connect_ui-0.9.1 vendor/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/paths.rb
zuora_connect_ui-0.9.0 vendor/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/paths.rb
zuora_connect_ui-0.8.3 vendor/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/paths.rb
zuora_connect_ui-0.8.2 vendor/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/paths.rb
zuora_connect_ui-0.8.1 vendor/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/paths.rb
zuora_connect_ui-0.8.0 vendor/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/paths.rb
spiral_form-0.1.1 vendor/bundle/gems/sprockets-3.7.2/lib/sprockets/paths.rb
spiral_form-0.1.0 vendor/bundle/gems/sprockets-3.7.2/lib/sprockets/paths.rb
zuora_connect_ui-0.7.1 vendor/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/paths.rb
zuora_connect_ui-0.7.0 vendor/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/paths.rb
tdiary-5.0.11 vendor/bundle/gems/sprockets-3.7.2/lib/sprockets/paths.rb
sprokovuln-0.2.0 vendor/ruby/gems/sprockets-3.7.1/lib/sprockets/paths.rb