class Pry::Command::SaveFile - pry-0.10.1 Documentation

# class Pry::Command::SaveFile

### Public Instance Methods

display_content() click to toggle source

    # File lib/pry/commands/save_file.rb, line 49
    def display_content
      output.puts @cc.content
      output.puts "\n\n--\nPlease use `--to FILE` to export to a file."
      output.puts "No file saved!\n--"
    end

file_name() click to toggle source

    # File lib/pry/commands/save_file.rb, line 38
    def file_name
      opts[:to] || nil
    end

mode() click to toggle source

    # File lib/pry/commands/save_file.rb, line 55
    def mode
      opts.present?(:append) ? "a" : "w"
    end

options(opt) click to toggle source

    # File lib/pry/commands/save_file.rb, line 20
    def options(opt)
      CodeCollector.inject_options(opt)

      opt.on :to=,        "Specify the output file path"
      opt.on :a, :append, "Append output to file"
    end

process() click to toggle source

    # File lib/pry/commands/save_file.rb, line 27
    def process
      @cc = CodeCollector.new(args, opts, _pry_)
      raise CommandError, "Found no code to save." if @cc.content.empty?

      if !file_name
        display_content
      else
        save_file
      end
    end

save_file() click to toggle source

    # File lib/pry/commands/save_file.rb, line 42
    def save_file
      File.open(file_name, mode) do |f|
        f.puts @cc.content
      end
      output.puts "#{file_name} successfully saved"
    end