Module: CFBundle::PathUtils
- Defined in:
- lib/cfbundle/path_utils.rb
Overview
Utility methods for manipulating paths
Class Method Summary collapse
-
.join(*args) ⇒ String
Returns a new path formed by joining the strings using
File::SEPARATOR. -
.join_resource(directory, name, product, extension) ⇒ String
Returns a new path formed by joining the resource components.
-
.split_resource(path, expected_product) ⇒ Array
Splits the resource path into four components.
Class Method Details
.join(*args) ⇒ String
Returns a new path formed by joining the strings using File::SEPARATOR.
The methods also makes sure to remove any trailing separator along with path components that are empty, nil or a single dot (.) in order to generate a canonical path.
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/cfbundle/path_utils.rb', line 16 def join(*args) args.compact! args.map! { |arg| arg.split(File::SEPARATOR) } args.flatten! args.reject! { |arg| arg == '.' } return '.' if args.empty? absolute = args.first == '' args.reject! { |arg| arg == '' } args.unshift('/') if absolute File.join(args) end |
.join_resource(directory, name, product, extension) ⇒ String
Returns a new path formed by joining the resource components.
56 57 58 59 |
# File 'lib/cfbundle/path_utils.rb', line 56 def join_resource(directory, name, product, extension) filename = [name, product, extension].join join(directory, filename) end |
.split_resource(path, expected_product) ⇒ Array
Splits the resource path into four components.
The components are the resource’s directory, name, product and extension. The product is either empty or starts with a tilde. The extension is either empty or starts with a dot.
37 38 39 40 41 42 43 44 45 |
# File 'lib/cfbundle/path_utils.rb', line 37 def split_resource(path, expected_product) directory = File.dirname(path) extension = File.extname(path) basename = File.basename(path, extension) name, product = split_resource_name_and_product( basename, expected_product ) [directory, name, product, extension] end |