Sha256: 99addd66079a68b9ee47338edb6f71c556b98b889e51f2c39ff452772b0ed831

Contents?: true

Size: 1.63 KB

Versions: 6770

Compression:

Stored size: 1.63 KB

Contents

# frozen_string_literal: true

require_relative "../command"

module Byebug
  #
  # Save current settings to use them in another debug session.
  #
  class SaveCommand < Command
    self.allow_in_control = true
    self.allow_in_post_mortem = true

    def self.regexp
      /^\s* sa(?:ve)? (?:\s+(\S+))? \s*$/x
    end

    def self.description
      <<-DESCRIPTION
        save[ FILE]

        #{short_description}

        Byebug state is saved as a script file. This includes breakpoints,
        catchpoints, display expressions and some settings. If no filename is
        given, byebug will fabricate one.

        Use the "source" command in another debug session to restore the saved
        file.
      DESCRIPTION
    end

    def self.short_description
      "Saves current byebug session to a file"
    end

    def execute
      file = File.open(@match[1] || Setting[:savefile], "w")

      save_breakpoints(file)
      save_catchpoints(file)
      save_displays(file)
      save_settings(file)

      print pr("save.messages.done", path: file.path)
      file.close
    end

    private

    def save_breakpoints(file)
      Byebug.breakpoints.each do |b|
        file.puts "break #{b.source}:#{b.pos}#{" if #{b.expr}" if b.expr}"
      end
    end

    def save_catchpoints(file)
      Byebug.catchpoints.each_key do |c|
        file.puts "catch #{c}"
      end
    end

    def save_displays(file)
      Byebug.displays.each { |d| file.puts "display #{d[1]}" if d[0] }
    end

    def save_settings(file)
      %w[autoirb autolist basename].each do |setting|
        file.puts "set #{setting} #{Setting[setting.to_sym]}"
      end
    end
  end
end

Version data entries

6,770 entries across 6,767 versions & 30 rubygems

Version Path
cybrid_api_id_ruby-0.123.104 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/commands/save.rb
cybrid_api_organization_ruby-0.123.104 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/commands/save.rb
cybrid_api_organization_ruby-0.123.103 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/commands/save.rb
cybrid_api_bank_ruby-0.123.103 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/commands/save.rb
cybrid_api_id_ruby-0.123.103 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/commands/save.rb
cybrid_api_bank_ruby-0.123.101 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/commands/save.rb
cybrid_api_id_ruby-0.123.101 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/commands/save.rb
cybrid_api_organization_ruby-0.123.101 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/commands/save.rb
cybrid_api_bank_ruby-0.123.100 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/commands/save.rb
cybrid_api_id_ruby-0.123.100 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/commands/save.rb
cybrid_api_organization_ruby-0.123.100 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/commands/save.rb
ory-client-1.15.16 vendor/bundle/ruby/3.1.0/gems/byebug-11.1.3/lib/byebug/commands/save.rb
cybrid_api_bank_ruby-0.123.99 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/commands/save.rb
cybrid_api_id_ruby-0.123.99 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/commands/save.rb
cybrid_api_organization_ruby-0.123.99 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/commands/save.rb
cybrid_api_bank_ruby-0.123.98 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/commands/save.rb
cybrid_api_organization_ruby-0.123.98 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/commands/save.rb
cybrid_api_id_ruby-0.123.98 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/commands/save.rb
cybrid_api_bank_ruby-0.123.97 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/commands/save.rb
cybrid_api_organization_ruby-0.123.97 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/commands/save.rb