Sha256: 3ac0b8102e069b7b03706cd804f1f6ba86e1814d00992ac06cba715b6daf6865

Contents?: true

Size: 1.46 KB

Versions: 6788

Compression:

Stored size: 1.46 KB

Contents

# frozen_string_literal: true

module Byebug
  module Helpers
    #
    # Utilities for interaction with files
    #
    module FileHelper
      #
      # Reads lines of source file +filename+ into an array
      #
      def get_lines(filename)
        File.foreach(filename).reduce([]) { |acc, elem| acc << elem.chomp }
      end

      #
      # Reads line number +lineno+ from file named +filename+
      #
      def get_line(filename, lineno)
        File.open(filename) do |f|
          f.gets until f.lineno == lineno - 1
          f.gets
        end
      end

      #
      # Returns the number of lines in file +filename+ in a portable,
      # one-line-at-a-time way.
      #
      def n_lines(filename)
        File.foreach(filename).reduce(0) { |acc, _elem| acc + 1 }
      end

      #
      # Regularize file name.
      #
      def normalize(filename)
        return filename if virtual_file?(filename)

        return File.basename(filename) if Setting[:basename]

        File.exist?(filename) ? File.realpath(filename) : filename
      end

      #
      # A short version of a long path
      #
      def shortpath(fullpath)
        components = Pathname(fullpath).each_filename.to_a
        return fullpath if components.size <= 2

        File.join("...", components[-3..-1])
      end

      #
      # True for special files like -e, false otherwise
      #
      def virtual_file?(name)
        ["(irb)", "-e", "(byebug)", "(eval)"].include?(name)
      end
    end
  end
end

Version data entries

6,788 entries across 6,784 versions & 35 rubygems

Version Path
ory-client-0.0.1.alpha38 vendor/bundle/ruby/2.5.0/gems/byebug-11.1.3/lib/byebug/helpers/file.rb
ory-client-0.0.1.alpha37 vendor/bundle/ruby/2.5.0/gems/byebug-11.1.3/lib/byebug/helpers/file.rb
ory-client-0.0.1.alpha36 vendor/bundle/ruby/2.5.0/gems/byebug-11.1.3/lib/byebug/helpers/file.rb
ory-kratos-client-0.8.2.alpha1 vendor/bundle/ruby/2.5.0/gems/byebug-11.1.3/lib/byebug/helpers/file.rb
ory-client-0.0.1.alpha31 vendor/bundle/ruby/2.5.0/gems/byebug-11.1.3/lib/byebug/helpers/file.rb
primary_connect_proto-0.4.0 vendor/bundle/ruby/2.6.0/gems/byebug-11.1.3/lib/byebug/helpers/file.rb
primary_connect_proto-0.3.0 vendor/bundle/ruby/2.6.0/gems/byebug-11.1.3/lib/byebug/helpers/file.rb
primary_connect_proto-0.2.0 vendor/bundle/ruby/2.6.0/gems/byebug-11.1.3/lib/byebug/helpers/file.rb
primary_connect_proto-0.1.0 vendor/bundle/ruby/2.6.0/gems/byebug-11.1.3/lib/byebug/helpers/file.rb
ory-client-0.0.1.alpha30 vendor/bundle/ruby/2.5.0/gems/byebug-11.1.3/lib/byebug/helpers/file.rb
ory-client-0.0.1.alpha29 vendor/bundle/ruby/2.5.0/gems/byebug-11.1.3/lib/byebug/helpers/file.rb
primary_connect_proto-0.0.6 vendor/bundle/ruby/2.6.0/gems/byebug-11.1.3/lib/byebug/helpers/file.rb
ory-client-0.0.1.alpha28 vendor/bundle/ruby/2.5.0/gems/byebug-11.1.3/lib/byebug/helpers/file.rb
primary_connect_proto-0.0.5 vendor/bundle/ruby/2.6.0/gems/byebug-11.1.3/lib/byebug/helpers/file.rb
ory-client-0.0.1.alpha27 vendor/bundle/ruby/2.5.0/gems/byebug-11.1.3/lib/byebug/helpers/file.rb
ory-client-0.0.1.alpha24 vendor/bundle/ruby/2.5.0/gems/byebug-11.1.3/lib/byebug/helpers/file.rb
primary_connect_proto-0.0.4 vendor/bundle/ruby/2.6.0/gems/byebug-11.1.3/lib/byebug/helpers/file.rb
primary_connect_proto-0.0.3 vendor/bundle/ruby/2.6.0/gems/byebug-11.1.3/lib/byebug/helpers/file.rb
date_n_time_picker_activeadmin-0.1.2 vendor/bundle/ruby/2.6.0/gems/byebug-11.1.3/lib/byebug/helpers/file.rb
date_n_time_picker_activeadmin-0.1.1 vendor/bundle/ruby/2.6.0/gems/byebug-11.1.3/lib/byebug/helpers/file.rb