Class: AmazingPrint::Formatters::DirFormatter

Inherits:
BaseFormatter show all
Defined in:
lib/amazing_print/formatters/dir_formatter.rb

Constant Summary

Constants inherited from BaseFormatter

BaseFormatter::DEFAULT_LIMIT_SIZE, BaseFormatter::INDENT_CACHE

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from BaseFormatter

#align, #colorless_size, #get_limit_size, #indent, #indentation, #indented, #limited, #method_tuple, #outdent, #should_be_limited?

Methods included from Colorize

#colorize

Constructor Details

#initialize(dir, inspector) ⇒ DirFormatter

Returns a new instance of DirFormatter.



13
14
15
16
17
18
# File 'lib/amazing_print/formatters/dir_formatter.rb', line 13

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

Instance Attribute Details

#dirObject (readonly)

Returns the value of attribute dir.



11
12
13
# File 'lib/amazing_print/formatters/dir_formatter.rb', line 11

def dir
  @dir
end

#inspectorObject (readonly)

Returns the value of attribute inspector.



11
12
13
# File 'lib/amazing_print/formatters/dir_formatter.rb', line 11

def inspector
  @inspector
end

#optionsObject (readonly)

Returns the value of attribute options.



11
12
13
# File 'lib/amazing_print/formatters/dir_formatter.rb', line 11

def options
  @options
end

Instance Method Details

#formatObject



20
21
22
23
# File 'lib/amazing_print/formatters/dir_formatter.rb', line 20

def format
  ls = info
  colorize(ls.empty? ? dir.inspect : "#{dir.inspect}\n#{ls.chop}", :dir)
end

#infoObject



25
26
27
28
29
30
31
# File 'lib/amazing_print/formatters/dir_formatter.rb', line 25

def info
  if RUBY_PLATFORM.include?('mswin')
    "#{GetChildItem.new(@dir.path)}\n"
  else
    `ls -alF #{dir.path.shellescape}`
  end
end