Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert a rails app to a gem?

I have a ruby on rails app that needs to be gem-ified. Jeweler, helps create basic rubygems. However, how do I package a rails app as a gem? I have a main app that requires my rails app as a gem. I cannot integrate them as the main rails app is to be used as a management app to control smaller apps, running in it as gems/engines.

like image 805
absessive Avatar asked Jul 16 '12 18:07

absessive


1 Answers

Since Rails 3.0 any Rails app is an Engine. For wrap your application to a gem you should:

  1. Create new gem with bundler or jeweler or something else.
  2. Insert your application code to lib/ directory of your gem.
  3. All classes of your app should be in MyGem module, so add MyGem before your class names, like: Article => MyGem::Article. All your controllers, models, etc. should be namespaced with module GemName.
  4. Your file lib/my_gem.rb should contain next code:

    module MyGem
      class Engine < Rails::Engine; end
    end
    

UPD

Or be better if you will use mountable engines:

$ rails plugin new MyGem

It generates mountable engine with dummy app for tests and gemspec.

like image 66
egoholic Avatar answered Sep 28 '22 06:09

egoholic