123456789_123456789_123456789_123456789_123456789_

Module: Sprockets::Paths

Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Extended In:
Included In:
Super Chains via Extension / Inclusion / Inheritance
Instance Chain:
self, PathUtils, Utils
Defined in: lib/sprockets/paths.rb

Constant Summary

Utils - Included

MODULE_INCLUDE_MUTEX, WHITESPACE_ORDINALS

PathUtils - Included

SEPARATOR_PATTERN

Instance Attribute Summary

Instance Method Summary

PathUtils - Included

#absolute_path?

On Windows, ALT_SEPARATOR is \ Delegate to Pathname since the logic gets complex.

#atomic_write

Public: Write to a file atomically.

#directory?

Public: Like File.directory?.

#entries

Public: A version of Dir.entries that filters out ‘.` files and ~ swap files.

#file?

Public: Like File.file?.

#find_matching_path_for_extensions

Internal: Match paths in a directory against available extensions.

#find_upwards

Internal: Find target basename checking upwards from path.

#join

Public: Joins path to base path.

#match_path_extname

Internal: Match path extnames against available extensions.

#path_extnames

Internal: Get path’s extensions.

#path_parents

Internal: Returns all parents for path.

#paths_split

Internal: Detect root path and base for file in a set of paths.

#relative_path?

Public: Check if path is explicitly relative.

#relative_path_from

Public: Get relative path from start to dest.

#set_pipeline

Public: Sets pipeline for path.

#split_subpath

Internal: Get relative path for root path and subpath.

#stat

Public: Like File.stat.

#stat_directory

Public: Stat all the files under a directory.

#stat_sorted_tree

Public: Recursive stat all the files under a directory in alphabetical order.

#stat_tree

Public: Recursive stat all the files under a directory.

Utils - Included

#concat_javascript_sources

Internal: Accumulate asset source to buffer and append a trailing semicolon if necessary.

#dfs

Internal: Post-order Depth-First search algorithm.

#dfs_paths

Internal: Post-order Depth-First search algorithm that gathers all paths along the way.

#duplicable?

Internal: Check if object can safely be .dup’d.

#hash_reassoc

Internal: Duplicate and store key/value on new frozen hash.

#hash_reassoc1

Internal: Duplicate and store key/value on new frozen hash.

#module_include

Internal: Inject into target module for the duration of the block.

#string_end_with_semicolon?

Internal: Check if string has a trailing semicolon.

Instance Attribute Details

#root (rw)

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)

[ GitHub ]

  
# File 'lib/sprockets/paths.rb', line 13

def root
  config[:root]
end

#root=(path) (rw, private)

Internal: Change Environment root.

Only the initializer should change the root.

[ GitHub ]

  
# File 'lib/sprockets/paths.rb', line 20

def root=(path)
  self.config = hash_reassoc(config, :root) do
    File.expand_path(path)
  end
end

Instance Method Details

#append_path(path)

Append a path to the #paths list.

Paths at the beginning of the Array have a higher priority.

[ GitHub ]

  
# File 'lib/sprockets/paths.rb', line 47

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_paths

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.

[ GitHub ]

  
# File 'lib/sprockets/paths.rb', line 59

def clear_paths
  self.config = hash_reassoc(config, :paths) do |paths|
    paths.clear
  end
end

#each_file

Public: Iterate over every file under all load paths.

Returns Enumerator if no block is given.

[ GitHub ]

  
# File 'lib/sprockets/paths.rb', line 68

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

#paths

Returns an Array of path Strings.

These paths will be used for asset logical path lookups.

[ GitHub ]

  
# File 'lib/sprockets/paths.rb', line 30

def paths
  config[:paths]
end

#prepend_path(path)

Prepend a path to the #paths list.

Paths at the end of the Array have the least priority.

[ GitHub ]

  
# File 'lib/sprockets/paths.rb', line 37

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