Class: Pry::Command::Cat::FileFormatter
- Inherits:
-
AbstractFormatter
- Object
- AbstractFormatter
- Pry::Command::Cat::FileFormatter
- Defined in:
- lib/pry/commands/cat/file_formatter.rb
Instance Attribute Summary collapse
-
#_pry_ ⇒ Object
readonly
Returns the value of attribute pry.
-
#file_with_embedded_line ⇒ Object
readonly
Returns the value of attribute file_with_embedded_line.
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
Instance Method Summary collapse
- #file_and_line ⇒ Object
- #format ⇒ Object
-
#initialize(file_with_embedded_line, _pry_, opts) ⇒ FileFormatter
constructor
A new instance of FileFormatter.
Methods included from Helpers::BaseHelpers
#colorize_code, #command_dependencies_met?, #find_command, #heading, #highlight, #jruby?, #jruby_19?, #linux?, #mac_osx?, #mri?, #mri_19?, #mri_2?, #not_a_real_file?, #safe_send, #silence_warnings, #stagger_output, #use_ansi_codes?, #windows?, #windows_ansi?
Methods included from Helpers::CommandHelpers
absolute_index_number, absolute_index_range, command_error, 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
Constructor Details
#initialize(file_with_embedded_line, _pry_, opts) ⇒ FileFormatter
Returns a new instance of FileFormatter.
8 9 10 11 12 13 14 15 |
# File 'lib/pry/commands/cat/file_formatter.rb', line 8 def initialize(, _pry_, opts) raise CommandError, "Must provide a filename, --in, or --ex." if ! @file_with_embedded_line = @opts = opts @_pry_ = _pry_ @code_from_file = Pry::Code.from_file(file_name) end |
Instance Attribute Details
#_pry_ ⇒ Object (readonly)
Returns the value of attribute pry.
6 7 8 |
# File 'lib/pry/commands/cat/file_formatter.rb', line 6 def _pry_ @_pry_ end |
#file_with_embedded_line ⇒ Object (readonly)
Returns the value of attribute file_with_embedded_line.
4 5 6 |
# File 'lib/pry/commands/cat/file_formatter.rb', line 4 def @file_with_embedded_line end |
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
5 6 7 |
# File 'lib/pry/commands/cat/file_formatter.rb', line 5 def opts @opts end |
Instance Method Details
#file_and_line ⇒ Object
22 23 24 25 26 |
# File 'lib/pry/commands/cat/file_formatter.rb', line 22 def file_and_line file_name, line_num = .split(/:(?!\/|\\)/) [file_name, line_num ? line_num.to_i : nil] end |
#format ⇒ Object
17 18 19 20 |
# File 'lib/pry/commands/cat/file_formatter.rb', line 17 def format set_file_and_dir_locals(file_name, _pry_, _pry_.current_context) decorate(@code_from_file) end |