Class: RrToRspecConverter::CLI
- Inherits:
-
Object
- Object
- RrToRspecConverter::CLI
- Defined in:
- lib/rr_to_rspec_converter/cli.rb
Instance Method Summary collapse
-
#initialize ⇒ CLI
constructor
A new instance of CLI.
- #log(str) ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize ⇒ CLI
Returns a new instance of CLI.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/rr_to_rspec_converter/cli.rb', line 8 def initialize @options = RrToRspecConverter::TextTransformerOptions.new OptionParser.new do |opts| opts. = "Usage: rr-to-rspec-converter [options] [files]" opts.on("--version", "Print version number") do |q| puts RrToRspecConverter::VERSION exit end opts.on("-q", "--quiet", "Run quietly") do |q| @options.quiet = q end end.parse! @files = ARGV end |
Instance Method Details
#log(str) ⇒ Object
42 43 44 45 46 |
# File 'lib/rr_to_rspec_converter/cli.rb', line 42 def log(str) return if @options.quiet? puts str end |
#run ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/rr_to_rspec_converter/cli.rb', line 26 def run paths = @files.length > 0 ? @files : ["spec/**/*.rb", "test/**/*.rb"] paths.each do |path| Dir.glob(path) do |file_path| log "Processing: #{file_path}" original_content = File.read(file_path) @options.file_path = file_path transformed_content = RrToRspecConverter::TextTransformer.new(original_content, @options).transform File.write(file_path, transformed_content) rescue Errno::EISDIR end end end |