Last active
December 17, 2015 16:59
-
-
Save jmgarnier/5642844 to your computer and use it in GitHub Desktop.
Use Case: you need to extract Rails engines from your kitchen sink webapp.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# Copy this file to the destination project folder | |
# Example: | |
# noglob ./import.rb *role* ../../project_source | |
# => copying app/models/role.rb | |
# => copying spec/models/role_spec.rb | |
require 'pathname' | |
require 'fileutils' | |
source_project = ARGV[1] || '../../SOURCE_PROJECT' | |
files_pattern_to_copy = ARGV.first | |
Dir["#{source_project}/**/#{files_pattern_to_copy}"].each do |file| | |
relative_source_project_path = file.gsub source_project, '' | |
source_project_dirname = Pathname.new(relative_source_project_path).dirname.to_s | |
puts "copying #{file} to #{source_project_dirname}" | |
FileUtils.mkdir_p "./#{source_project_dirname}" | |
FileUtils.cp_r file, "./#{source_project_dirname}/" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment