summaryrefslogtreecommitdiff
path: root/lib/pry/commands/save_file.rb
diff options
context:
space:
mode:
authorKyrylo Silin <silin@kyrylo.org>2019-02-27 02:22:32 +0200
committerKyrylo Silin <silin@kyrylo.org>2019-02-27 02:23:52 +0200
commitb98cff1b85aeacebcf7bc8c5d13c524814672173 (patch)
tree869f42b628cf6467045ea42b6410093a01de6698 /lib/pry/commands/save_file.rb
parent4068d96ee8c859d3af5000a39e351b320d74e941 (diff)
downloadpry-b98cff1b85aeacebcf7bc8c5d13c524814672173.tar.gz
rubocop: fix offences of the Style/ClassAndModuleChildren cop
Diffstat (limited to 'lib/pry/commands/save_file.rb')
-rw-r--r--lib/pry/commands/save_file.rb86
1 files changed, 44 insertions, 42 deletions
diff --git a/lib/pry/commands/save_file.rb b/lib/pry/commands/save_file.rb
index d22a6924..6d3ab689 100644
--- a/lib/pry/commands/save_file.rb
+++ b/lib/pry/commands/save_file.rb
@@ -1,61 +1,63 @@
require 'pry/commands/code_collector'
class Pry
- class Command::SaveFile < Pry::ClassCommand
- match 'save-file'
- group 'Input and Output'
- description 'Export to a file using content from the REPL.'
+ class Command
+ class SaveFile < Pry::ClassCommand
+ match 'save-file'
+ group 'Input and Output'
+ description 'Export to a file using content from the REPL.'
- banner <<-'BANNER'
- Usage: save-file [OPTIONS] --to [FILE]
+ banner <<-'BANNER'
+ Usage: save-file [OPTIONS] --to [FILE]
- Export to a file using content from the REPL.
+ Export to a file using content from the REPL.
- save-file my_method --to hello.rb
- save-file -i 1..10 --to hello.rb --append
- save-file show-method --to my_command.rb
- save-file sample_file.rb --lines 2..10 --to output_file.rb
- BANNER
+ save-file my_method --to hello.rb
+ save-file -i 1..10 --to hello.rb --append
+ save-file show-method --to my_command.rb
+ save-file sample_file.rb --lines 2..10 --to output_file.rb
+ BANNER
- def options(opt)
- CodeCollector.inject_options(opt)
+ def options(opt)
+ CodeCollector.inject_options(opt)
- opt.on :to=, "Specify the output file path"
- opt.on :a, :append, "Append output to file"
- end
+ opt.on :to=, "Specify the output file path"
+ opt.on :a, :append, "Append output to file"
+ end
- def process
- @cc = CodeCollector.new(args, opts, _pry_)
- raise CommandError, "Found no code to save." if @cc.content.empty?
+ 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
+ if !file_name
+ display_content
+ else
+ save_file
+ end
end
- end
- def file_name
- opts[:to] || nil
- end
+ def file_name
+ opts[:to] || nil
+ end
- def save_file
- File.open(file_name, mode) do |f|
- f.puts @cc.content
+ def save_file
+ File.open(file_name, mode) do |f|
+ f.puts @cc.content
+ end
+ output.puts "#{file_name} successfully saved"
end
- output.puts "#{file_name} successfully saved"
- end
- 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
+ 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
- def mode
- opts.present?(:append) ? "a" : "w"
+ def mode
+ opts.present?(:append) ? "a" : "w"
+ end
end
- end
- Pry::Commands.add_command(Pry::Command::SaveFile)
+ Pry::Commands.add_command(Pry::Command::SaveFile)
+ end
end