Class: Pry::Command::Cat::FileFormatter

Inherits:
AbstractFormatter show all
Defined in:
lib/pry/commands/cat/file_formatter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers::BaseHelpers

#colorize_code, #find_command, #heading, #highlight, #not_a_real_file?, #safe_send, #silence_warnings, #stagger_output, #use_ansi_codes?

Methods included from Helpers::CommandHelpers

#absolute_index_number, #absolute_index_range, #get_method_or_raise, #internal_binding?, #one_index_number, #one_index_range, #one_index_range_or_number, #restrict_to_lines, #set_file_and_dir_locals, #temp_file, #unindent

Methods included from Helpers::OptionsHelpers

method_object, method_options

Constructor Details

#initialize(file_with_embedded_line, pry_instance, opts) ⇒ FileFormatter

Returns a new instance of FileFormatter.



11
12
13
14
15
16
17
18
19
20
# File 'lib/pry/commands/cat/file_formatter.rb', line 11

def initialize(file_with_embedded_line, pry_instance, opts)
  unless file_with_embedded_line
    raise CommandError, "Must provide a filename, --in, or --ex."
  end

  @file_with_embedded_line = file_with_embedded_line
  @opts = opts
  @pry_instance = pry_instance
  @code_from_file = Pry::Code.from_file(file_name)
end

Instance Attribute Details

#file_with_embedded_lineObject (readonly)

Returns the value of attribute file_with_embedded_line.



7
8
9
# File 'lib/pry/commands/cat/file_formatter.rb', line 7

def file_with_embedded_line
  @file_with_embedded_line
end

#optsObject (readonly)

Returns the value of attribute opts.



8
9
10
# File 'lib/pry/commands/cat/file_formatter.rb', line 8

def opts
  @opts
end

#pry_instanceObject (readonly)

Returns the value of attribute pry_instance.



9
10
11
# File 'lib/pry/commands/cat/file_formatter.rb', line 9

def pry_instance
  @pry_instance
end

Instance Method Details

#file_and_lineObject



27
28
29
30
31
# File 'lib/pry/commands/cat/file_formatter.rb', line 27

def file_and_line
  file_name, line_num = file_with_embedded_line.split(%r{:(?!/|\\)})

  [file_name, line_num ? line_num.to_i : nil]
end

#formatObject



22
23
24
25
# File 'lib/pry/commands/cat/file_formatter.rb', line 22

def format
  set_file_and_dir_locals(file_name, pry_instance, pry_instance.current_context)
  decorate(@code_from_file)
end