diff options
author | Kyrylo Silin <silin@kyrylo.org> | 2019-02-27 02:22:32 +0200 |
---|---|---|
committer | Kyrylo Silin <silin@kyrylo.org> | 2019-02-27 02:23:52 +0200 |
commit | b98cff1b85aeacebcf7bc8c5d13c524814672173 (patch) | |
tree | 869f42b628cf6467045ea42b6410093a01de6698 /lib/pry/commands/cat.rb | |
parent | 4068d96ee8c859d3af5000a39e351b320d74e941 (diff) | |
download | pry-b98cff1b85aeacebcf7bc8c5d13c524814672173.tar.gz |
rubocop: fix offences of the Style/ClassAndModuleChildren cop
Diffstat (limited to 'lib/pry/commands/cat.rb')
-rw-r--r-- | lib/pry/commands/cat.rb | 108 |
1 files changed, 55 insertions, 53 deletions
diff --git a/lib/pry/commands/cat.rb b/lib/pry/commands/cat.rb index 5d53ace7..4bc445f5 100644 --- a/lib/pry/commands/cat.rb +++ b/lib/pry/commands/cat.rb @@ -1,63 +1,65 @@ class Pry - class Command::Cat < Pry::ClassCommand - require 'pry/commands/cat/abstract_formatter.rb' - require 'pry/commands/cat/input_expression_formatter.rb' - require 'pry/commands/cat/exception_formatter.rb' - require 'pry/commands/cat/file_formatter.rb' - - match 'cat' - group 'Input and Output' - description "Show code from a file, Pry's input buffer, or the last exception." - - banner <<-'BANNER' - Usage: cat FILE - cat --ex [STACK_INDEX] - cat --in [INPUT_INDEX_OR_RANGE] - - `cat` is capable of showing part or all of a source file, the context of the - last exception, or an expression from Pry's input history. - - `cat --ex` defaults to showing the lines surrounding the location of the last - exception. Invoking it more than once travels up the exception's backtrace, and - providing a number shows the context of the given index of the backtrace. - BANNER - - def options(opt) - opt.on :ex, "Show the context of the last exception", optional_argument: true, as: Integer - opt.on :i, :in, "Show one or more entries from Pry's expression history", optional_argument: true, as: Range, default: -5..-1 - opt.on :s, :start, "Starting line (defaults to the first line)", optional_argument: true, as: Integer - opt.on :e, :end, "Ending line (defaults to the last line)", optional_argument: true, as: Integer - opt.on :l, :'line-numbers', "Show line numbers" - opt.on :t, :type, "The file type for syntax highlighting (e.g., 'ruby' or 'python')", argument: true, as: Symbol - end + class Command + class Cat < Pry::ClassCommand + require 'pry/commands/cat/abstract_formatter.rb' + require 'pry/commands/cat/input_expression_formatter.rb' + require 'pry/commands/cat/exception_formatter.rb' + require 'pry/commands/cat/file_formatter.rb' - def process - output = case - when opts.present?(:ex) - ExceptionFormatter.new(_pry_.last_exception, _pry_, opts).format - when opts.present?(:in) - InputExpressionFormatter.new(_pry_.input_ring, opts).format - else - FileFormatter.new(args.first, _pry_, opts).format - end - - _pry_.pager.page output - end + match 'cat' + group 'Input and Output' + description "Show code from a file, Pry's input buffer, or the last exception." - def complete(search) - super | load_path_completions - end + banner <<-'BANNER' + Usage: cat FILE + cat --ex [STACK_INDEX] + cat --in [INPUT_INDEX_OR_RANGE] + + `cat` is capable of showing part or all of a source file, the context of the + last exception, or an expression from Pry's input history. + + `cat --ex` defaults to showing the lines surrounding the location of the last + exception. Invoking it more than once travels up the exception's backtrace, and + providing a number shows the context of the given index of the backtrace. + BANNER + + def options(opt) + opt.on :ex, "Show the context of the last exception", optional_argument: true, as: Integer + opt.on :i, :in, "Show one or more entries from Pry's expression history", optional_argument: true, as: Range, default: -5..-1 + opt.on :s, :start, "Starting line (defaults to the first line)", optional_argument: true, as: Integer + opt.on :e, :end, "Ending line (defaults to the last line)", optional_argument: true, as: Integer + opt.on :l, :'line-numbers', "Show line numbers" + opt.on :t, :type, "The file type for syntax highlighting (e.g., 'ruby' or 'python')", argument: true, as: Symbol + end - def load_path_completions - $LOAD_PATH.flat_map do |path| - Dir[path + '/**/*'].map do |f| - next if File.directory?(f) + def process + output = case + when opts.present?(:ex) + ExceptionFormatter.new(_pry_.last_exception, _pry_, opts).format + when opts.present?(:in) + InputExpressionFormatter.new(_pry_.input_ring, opts).format + else + FileFormatter.new(args.first, _pry_, opts).format + end - f.sub!(path + '/', '') + _pry_.pager.page output + end + + def complete(search) + super | load_path_completions + end + + def load_path_completions + $LOAD_PATH.flat_map do |path| + Dir[path + '/**/*'].map do |f| + next if File.directory?(f) + + f.sub!(path + '/', '') + end end end end - end - Pry::Commands.add_command(Pry::Command::Cat) + Pry::Commands.add_command(Pry::Command::Cat) + end end |