How do I copy a file from a gem to my rails application using rake
Asked Answered
T

1

9

I have a gem with a default configuration YAML file, some_config.yml. I want to create a rake task to copy that file into the config/ directory of my rails application. How can I achieve this?

Transformation answered 29/8, 2012 at 16:39 Comment(0)
O
11

If we assume the target gem is in your Gemfile and you want to include the Rake task in your Rails Rakefile, then you could try something like:

namespace :config do
  # desc "Copy the config"
  task :copy do
    source = File.join(Gem.loaded_specs["myGem"].full_gem_path, "config", "config.yml")
    target = File.join(Rails.root, "config", "myGemConfig.yml")
    FileUtils.cp_r source, target
  end
end
Orthogenesis answered 14/11, 2012 at 22:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.