Class: AmazingPrint::Formatters::FileFormatter

Inherits:
BaseFormatter show all
Defined in:
lib/amazing_print/formatters/file_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, #get_limit_size, #indent, #indentation, #indented, #limited, #method_tuple, #outdent, #should_be_limited?

Methods included from Colorize

#colorize

Constructor Details

#initialize(file, inspector) ⇒ FileFormatter

Returns a new instance of FileFormatter.


9
10
11
12
13
# File 'lib/amazing_print/formatters/file_formatter.rb', line 9

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

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file


7
8
9
# File 'lib/amazing_print/formatters/file_formatter.rb', line 7

def file
  @file
end

#inspectorObject (readonly)

Returns the value of attribute inspector


7
8
9
# File 'lib/amazing_print/formatters/file_formatter.rb', line 7

def inspector
  @inspector
end

#optionsObject (readonly)

Returns the value of attribute options


7
8
9
# File 'lib/amazing_print/formatters/file_formatter.rb', line 7

def options
  @options
end

Instance Method Details

#formatObject


15
16
17
18
# File 'lib/amazing_print/formatters/file_formatter.rb', line 15

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