class Byebug::InfoCommand::FileCommand - byebug-9.0.6 Documentation

# class Byebug::InfoCommand::FileCommand

Information about a particular source file

### Public Class Methods

description() click to toggle source

    # File lib/byebug/commands/info/file.rb, line 20
    def self.description
      <<-EOD
        inf[o] f[ile]

        #{short_description}

        It informs about file name, number of lines, possible breakpoints in
        the file, last modification time and sha1 digest.
      EOD
    end

regexp() click to toggle source

    # File lib/byebug/commands/info/file.rb, line 16
    def self.regexp
      /^\s* f(?:ile)? (?:\s+ (.+))? \s*$/x
    end

short_description() click to toggle source

    # File lib/byebug/commands/info/file.rb, line 31
    def self.short_description
      'Information about a particular source file.'
    end

### Public Instance Methods

execute() click to toggle source

    # File lib/byebug/commands/info/file.rb, line 35
          def execute
            file = @match[1] || frame.file
            unless File.exist?(file)
              return errmsg(pr('info.errors.undefined_file', file: file))
            end

            puts "
              File #{info_file_basic(file)}

              Breakpoint line numbers: #{info_file_breakpoints(file)}

              Modification time: #{info_file_mtime(file)}

              Sha1 Signature: #{info_file_sha1(file)}

    ".gsub(/^ {6}/, '')
          end

### Private Instance Methods

info_file_basic(file) click to toggle source

    # File lib/byebug/commands/info/file.rb, line 56
    def info_file_basic(file)
      path = File.expand_path(file)
      return unless File.exist?(path)

      s = n_lines(path) == 1 ? '' : 's'
      "#{path} (#{n_lines(path)} line#{s})"
    end

info_file_breakpoints(file) click to toggle source

    # File lib/byebug/commands/info/file.rb, line 64
    def info_file_breakpoints(file)
      breakpoints = Breakpoint.potential_lines(file)
      return unless breakpoints

      breakpoints.to_a.sort.join(' ')
    end

info_file_mtime(file) click to toggle source

    # File lib/byebug/commands/info/file.rb, line 71
    def info_file_mtime(file)
      File.stat(file).mtime
    end

info_file_sha1(file) click to toggle source

    # File lib/byebug/commands/info/file.rb, line 75
    def info_file_sha1(file)
      require 'digest/sha1'
      Digest::SHA1.hexdigest(file)
    end