Skip to content

Instantly share code, notes, and snippets.

@jmgarnier
Last active December 17, 2015 16:59
Show Gist options
  • Save jmgarnier/5642844 to your computer and use it in GitHub Desktop.
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.
#!/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