Method: Synvert::Core::Rewriter#within_files

Defined in:
lib/synvert/core/rewriter.rb

#within_files(file_patterns, &block) ⇒ Object Also known as: within_file

It finds specified files, and for each file, it will delegate to Instance to rewrite code. It creates a Instance to rewrite code.

Examples:

Synvert::Rewriter.new 'rspec', 'be_close_to_be_within' do
  within_files '**/*.rb' do
  end
end

Parameters:

  • file_patterns (String|Array<String>)

    string pattern or list of string pattern to find files, e.g. ['spec/*/_spec.rb']

  • block (Block)

    the block to rewrite code in the matching files.



254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
# File 'lib/synvert/core/rewriter.rb', line 254

def within_files(file_patterns, &block)
  return unless @options[:run_instance]

  return if @ruby_version && !@ruby_version.match?
  return if @gem_spec && !@gem_spec.match?

  if @options[:write_to_file]
    handle_one_file(Array(file_patterns)) do |file_path|
      instance = Instance.new(self, file_path, &block)
      instance.process
    end
  else
    results =
      handle_one_file(Array(file_patterns)) do |file_path|
        instance = Instance.new(self, file_path, &block)
        instance.test
      end
    merge_test_results(results)
  end
end