awesome-print/awesome_print

View on GitHub
lib/awesome_print/formatters/dir_formatter.rb

Summary

Maintainability
A
0 mins
Test Coverage
require_relative 'base_formatter'
require 'shellwords'

module AwesomePrint
  module Formatters
    class DirFormatter < BaseFormatter

      attr_reader :dir, :inspector, :options

      def initialize(dir, inspector)
        @dir = dir
        @inspector = inspector
        @options = inspector.options
      end

      def format
        ls = `ls -alF #{dir.path.shellescape}`
        colorize(ls.empty? ? dir.inspect : "#{dir.inspect}\n#{ls.chop}", :dir)
      end
    end
  end
end