Module: Juicer::Command::Util
Overview
Utilities for Juicer command objects
Instance Method Summary collapse
-
#files(*args) ⇒ Object
Returns an array of files from a variety of input.
-
#relative(paths, reference_path = Dir.pwd) ⇒ Object
Uses Pathname to calculate the shortest relative path from
path
toreference_path
(default isDir.cwd
).
Instance Method Details
#files(*args) ⇒ Object
Returns an array of files from a variety of input. Input may be a single file, a single glob pattern or multiple files and/or patterns. It may even be an array of mixed input.
12 13 14 |
# File 'lib/juicer/command/util.rb', line 12 def files(*args) args.flatten.collect { |file| Dir.glob(file) }.flatten end |
#relative(paths, reference_path = Dir.pwd) ⇒ Object
Uses Pathname to calculate the shortest relative path from path
to reference_path
(default is Dir.cwd
)
20 21 22 23 24 25 26 27 28 |
# File 'lib/juicer/command/util.rb', line 20 def relative(paths, reference_path = Dir.pwd) paths = [paths].flatten.collect do |path| path = Pathname.new(File.(path)) reference_path = Pathname.new(File.(reference_path)) path.relative_path_from(reference_path).to_s end paths.length == 1 ? paths.first : paths end |