First you need to define a generator in lib / generators / your_gem_name_generator.rb
mkdir -p lib/generators/
Copy your initializer in this folder with a name like twitter_credentials.rb
Then create another file in this folder with a name like twitter_generator.rb with content like this:
class YourGemNameRailtie < Rails::Generators::Base source_root(File.expand_path(File.dirname(__FILE__)) def copy_initializer copy_file 'twitter_credentials.rb', 'config/initializers/twitter_credentials.rb' end end
You should check the official documentation for creating the generator here: http://guides.rubyonrails.org/generators.html
source share