Sha256: 19e85c04e3d86a42d8e60048f68a9f042e4cf84d69e0fd1f6feedfe00249e88f

Contents?: true

Size: 937 Bytes

Versions: 40

Compression:

Stored size: 937 Bytes

Contents

require "pathname"

module Juicer
  module Command
    # Utilities for Juicer command objects
    #
    module Util
      # 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.
      #
      def files(*args)
        args.flatten.collect { |file| Dir.glob(file) }.flatten
      end

      #
      # Uses Pathname to calculate the shortest relative path from +path+ to
      # +reference_path+ (default is +Dir.cwd+)
      #
      def relative(paths, reference_path = Dir.pwd)
        paths = [paths].flatten.collect do |path|
          path = Pathname.new(File.expand_path(path))
          reference_path = Pathname.new(File.expand_path(reference_path))
          path.relative_path_from(reference_path).to_s
        end

        paths.length == 1 ? paths.first : paths
      end
    end
  end
end

Version data entries

40 entries across 40 versions & 4 rubygems

Version Path
juicer-1.2.0 lib/juicer/command/util.rb
cjohansen-juicer-0.2.4 lib/juicer/command/util.rb
cjohansen-juicer-0.2.5 lib/juicer/command/util.rb
juicer-1.1.2 lib/juicer/command/util.rb
juicer-1.1.1 lib/juicer/command/util.rb
juicer-1.1.0 lib/juicer/command/util.rb
juicer-1.0.22 lib/juicer/command/util.rb
juicer-1.0.21 lib/juicer/command/util.rb
juicer-1.0.20 lib/juicer/command/util.rb
juicer-1.0.19 lib/juicer/command/util.rb
juicer-1.0.18 lib/juicer/command/util.rb
juicer-1.0.17 lib/juicer/command/util.rb
juicer-1.0.16 lib/juicer/command/util.rb
juicer-1.0.15 lib/juicer/command/util.rb
juicer-1.0.14 lib/juicer/command/util.rb
juicer-1.0.13 lib/juicer/command/util.rb
psyho_juicer-1.0.11 lib/juicer/command/util.rb
juicer-1.0.12 lib/juicer/command/util.rb
juicer-1.0.11 lib/juicer/command/util.rb
juicer-1.0.10 lib/juicer/command/util.rb