How to Convert a Large Gem to Standalone Rails App

How to convert a large gem to standalone rails app

I would suggest that you clone the gem and begin copying files from the gem into your a new Rails application.

The engine gem probably has a similar structure to a Rails application, so you should be able to move the files from the corresponding folder to the same folder in your Rails root folder.

You may need to move gem files out of modules, change namespaces etc. Relevant folders to look at files you'll want to include might include app/ config/ db/, any gem dependencies in Gemfile or the gemspec file, as well as spec/ or test/.

Beyond that I think there's no silver bullet answer to your question, you're just going to have to work through problems until you have this up and running, and perhaps ask subsequent questions if you hit on an obstacle that you don't get beyond.

How to convert a rails app to a gem?

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.

How to release large Ruby Gem?

You can ask your users to install the gem from git (bundler: http://bundler.io/git.html, Install Gem from Github Branch?).

This will result in a line like

gem 'hard_drive_expander', github: 'rodrigo/hard_drive_expander'

in a Gemfile (or a bit a lengthier process for gem install - do you intend 'library' kind of usage or standalone installations). Note that depending on your scenario you could have an installer gem that depends on the "github-hosted" gem, or downloads and builds/installs it (both seem like dirty solutions to me though, its not what I expect or commonly see).

Although github does place quotas on your repositories, you will probably not hit them (https://help.github.com/articles/what-is-my-disk-quota/).

Another option is to host it yourself (http://guides.rubygems.org/run-your-own-gem-server/).

Sorry for the "linky" answer.

However, @icguida and @engineersmnky s comments to your question are very worth considering: Do you really need to include chromium?

Update

There is a gem that will hook into gem to allow for usage like this: gem specific_install https://github.com/githubsvnclone/rdoc.git. The gem is called specific_install: https://github.com/rdp/specific_install .

Best practice for importing a partial database dump into a rails app daily?

Rails Engines might be a good fit for this. You can create a Rails Engine gem and add all of your models and rake tasks to consume the data. Then you can include this gem in any app that uses it and also create an API app which includes the gem. You should be able to create observers in your other apps that interact with the gem.

I have quite a few apps that interact with each other and this approach works well for me. I have one central app that includes all the engines that consume data and I run all of my cronjobs from this app. I use the use_db plugin which allows my app to communicate with different databases. Each engine has use_db as a dependency and I keep the database configuration inside the gem. One example:

  1. Engine Gem = transaction_core
  2. This gem consumes transaction data from a source and inserts it into my transaction database.
  3. The gem is included in my central app and I pull the transaction data using a rake task on the cron
  4. I include this gem in several other apps that need to use the transaction data. Since the engine automatically adds the models and database config to the app, there is no additional work required to use the models in the app.

I have not used observers inside an app that includes my engines, but I see no reason why it would not work. With the engine the models work as if they are in your app/models directory. Hope this helps!

Modest Rubyist has a good 4 part tutorial on Rails 3 plugins that includes Engines:

http://www.themodestrubyist.com/2010/03/05/rails-3-plugins---part-2---writing-an-engine/

How to distribute a Ruby script with required gems

I'm operating off of the assumption that your required gems are in a Gemfile. If you're having them run a bash script to run your Ruby script, have you considered adding bundle install to the bash script prior to having it run your Ruby script? This will install all the required gems before running the script.

Another option would be to setup a Docker container that already has all the gems installed and just automatically runs the Ruby script. This would get you around issues with your users having the wrong version of Ruby, but has the added cost of having them install Docker.

How do I handle recurring/subscription billing in a Rails App?

You can look into Saasy. It's a stand alone Rails app (not a plugin) that you host on a subdomain and communicate with it using SSO/REST protocols. Probably won't fit your need as it is, but you may be able to extend it or get a general idea of how it works.



Related Topics



Leave a reply



Submit