Sha256: 717385524bb510111bf1e552b8a89da0acaa4aaf9b6c9e77935f90fc0241f531

Contents?: true

Size: 1.56 KB

Versions: 110

Compression:

Stored size: 1.56 KB

Contents

class Pry
  class Command::Cat
    class FileFormatter < AbstractFormatter
      attr_reader :file_with_embedded_line
      attr_reader :opts
      attr_reader :_pry_

      def initialize(file_with_embedded_line, _pry_, opts)
        @file_with_embedded_line = file_with_embedded_line
        @opts = opts
        @_pry_ = _pry_
        @code_from_file = Pry::Code.from_file(file_name)
      end

      def format
        raise CommandError, "Must provide a filename, --in, or --ex." if !file_with_embedded_line

        set_file_and_dir_locals(file_name, _pry_, _pry_.current_context)
        decorate(@code_from_file)
      end

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

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

      private

      def file_name
        file_and_line.first
      end

      def line_number
        file_and_line.last
      end

      def code_window_size
        _pry_.config.default_window_size || 7
      end

      def decorate(content)
        line_number ? super.around(line_number, code_window_size) : super
      end

      def code_type
        opts[:type] || detect_code_type_from_file(file_name)
      end

      def detect_code_type_from_file(file_name)
        code_type = @code_from_file.code_type

        if code_type == :unknown
          name = File.basename(file_name).split('.', 2).first
          case name
          when "Rakefile", "Gemfile"
            :ruby
          else
            :text
          end
        else
          code_type
        end
      end
    end
  end
end

Version data entries

110 entries across 103 versions & 28 rubygems

Version Path
logstash-output-scalyr-0.2.1.beta vendor/bundle/jruby/2.5.0/gems/pry-0.10.4-java/lib/pry/commands/cat/file_formatter.rb
logstash-output-scalyr-0.2.0 vendor/bundle/jruby/2.5.0/gems/pry-0.10.4-java/lib/pry/commands/cat/file_formatter.rb
logstash-output-scalyr-0.2.0.beta vendor/bundle/jruby/2.5.0/gems/pry-0.10.4-java/lib/pry/commands/cat/file_formatter.rb
logstash-output-scalyr-0.1.26.beta vendor/bundle/jruby/2.5.0/gems/pry-0.10.4-java/lib/pry/commands/cat/file_formatter.rb
logstash-output-scalyr-0.1.25.beta vendor/bundle/jruby/2.5.0/gems/pry-0.10.4-java/lib/pry/commands/cat/file_formatter.rb
logstash-output-scalyr-0.1.24.beta vendor/bundle/jruby/2.5.0/gems/pry-0.10.4-java/lib/pry/commands/cat/file_formatter.rb
logstash-output-scalyr-0.1.23.beta vendor/bundle/jruby/2.5.0/gems/pry-0.10.4-java/lib/pry/commands/cat/file_formatter.rb
logstash-output-scalyr-0.1.22.beta vendor/bundle/jruby/2.5.0/gems/pry-0.10.4-java/lib/pry/commands/cat/file_formatter.rb
logstash-output-scalyr-0.1.21.beta vendor/bundle/jruby/2.5.0/gems/pry-0.10.4-java/lib/pry/commands/cat/file_formatter.rb
logstash-output-scalyr-0.1.20.beta vendor/bundle/jruby/2.5.0/gems/pry-0.10.4-java/lib/pry/commands/cat/file_formatter.rb
logstash-output-scalyr-0.1.19.beta vendor/bundle/jruby/2.5.0/gems/pry-0.10.4-java/lib/pry/commands/cat/file_formatter.rb
logstash-output-scalyr-0.1.18.beta vendor/bundle/jruby/2.5.0/gems/pry-0.10.4-java/lib/pry/commands/cat/file_formatter.rb
logstash-output-scalyr-0.1.17.beta vendor/bundle/jruby/2.5.0/gems/pry-0.10.4-java/lib/pry/commands/cat/file_formatter.rb
logstash-output-scalyr-0.1.16.beta vendor/bundle/jruby/2.5.0/gems/pry-0.10.4-java/lib/pry/commands/cat/file_formatter.rb
logstash-output-scalyr-0.1.15.beta vendor/bundle/jruby/2.5.0/gems/pry-0.10.4-java/lib/pry/commands/cat/file_formatter.rb
logstash-output-scalyr-0.1.14.beta vendor/bundle/jruby/2.5.0/gems/pry-0.10.4-java/lib/pry/commands/cat/file_formatter.rb
logstash-output-scalyr-0.1.13 vendor/bundle/jruby/2.5.0/gems/pry-0.10.4-java/lib/pry/commands/cat/file_formatter.rb
logstash-output-scalyr-0.1.12 vendor/bundle/jruby/2.5.0/gems/pry-0.10.4-java/lib/pry/commands/cat/file_formatter.rb
logstash-output-scalyr-0.1.11.beta vendor/bundle/jruby/2.5.0/gems/pry-0.10.4-java/lib/pry/commands/cat/file_formatter.rb
logstash-output-scalyr-0.1.10.beta vendor/bundle/jruby/2.5.0/gems/pry-0.10.4-java/lib/pry/commands/cat/file_formatter.rb