class Pry::Command::SaveFile
Public Instance Methods
display_content()
click to toggle source
# File lib/pry/commands/save_file.rb, line 50 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 39 def file_name opts[:to] || nil end
mode()
click to toggle source
# File lib/pry/commands/save_file.rb, line 56 def mode opts.present?(:append) ? "a" : "w" end
options(opt)
click to toggle source
# File lib/pry/commands/save_file.rb, line 21 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 28 def process @cc = CodeCollector.new(args, opts, pry_instance) 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 43 def save_file File.open(file_name, mode) do |f| f.puts @cc.content end output.puts "#{file_name} successfully saved" end