Sha256: 1d541d0ebb94211720fc86500f98c73821b20b6b87d18bb6f92081fd7e533fbd

Contents?: true

Size: 1.16 KB

Versions: 3

Compression:

Stored size: 1.16 KB

Contents

module DRG
  module Tasks
    class UpgradeFile
      include Log

      attr_accessor :file

      def initialize(file_name)
        @file = Bundler.root.join(file_name.to_s)
      end

      def call
        ruby_files.each do |ruby_file|
          contents = File.read(ruby_file)
          log %(Updating "#{ruby_file}")
          contents.gsub! /:(\w+)\s?=>/, '\1:'
          # contents.gsub!(/([A-Z]*[a-z0-9_!?.\[\]'()+=>:,&]+)\.(should)\s?==/, 'expect(\1).to eq')
          contents.gsub! /Factory\.create/, 'create'
          contents.gsub! /Factory\.build/, 'build'
          contents.gsub! /Factory\.next/, 'generate'
          contents.gsub! /Factory\(/, 'create('
          contents.gsub! /Factory\.attributes_for/, 'FactoryGirl.attributes_for'
          File.write(ruby_file, contents)
        end
        if ruby_files.empty?
          log %(No files found for "#{file}")
        end
        log 'Done.'
      end

      def ruby_files
        if File.directory?(file)
          Dir[File.join(file, '**', '*.rb')]
        else
          if file.extname.empty?
            ["#{file}.rb"]
          else
            [file]
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
drg-1.6.0 lib/drg/tasks/upgrade_file.rb
drg-1.5.2 lib/drg/tasks/upgrade_file.rb
drg-1.5.1 lib/drg/tasks/upgrade_file.rb