How to install a forked gem on Engine Yard? - ruby-on-rails

I want to use the LinkedIn gem But not the one that I get when I type
sudo gem install linkedin
I want a specific one that somehow has done patches to. It is a fork of the original which is:
http://github.com/jbasdf/linkedin
I have downloaded sources from the above link, and use "rake" command to build a gem locally. So everything is working fine locally.
But now I have a question. How can I setup this folked gem on the server (engine yard)? I am not sure how to bild a gem on the server in this case.
Many thanks!

If the pre-built gem is available on a server(gem cutter) you should be able to use Trip's method.
If not two options spring to my mind:
1) Write a chef script that clones the source from github and builds it.
2) Use bundler with its built in support for building gems from a git url. EY fully supports bundler.
I think the latter would be a better choice, as it completely removes the need to use EY's UI for managing gems and is a step towards Rails 3 compatibility.

You can log into EY's cpanel. On your dashboard, Click "Application" in your instance, and then click on the Ruby Gem Icon. In this panel you can download gems to install on your server including what version you want them as well.

Related

Ruby gem common deployement for all apps

I am trying to deploy APM solution provided by scout app. Scout apm documentation says I need to install a gem in all the applications I am running on the server. I have multiple applications running on single server. All my ruby applications are located at /var/www. Is there a way I can deploy that apm gem in one place and then it can be used for all the services. so that I don't need to add it in each application Gemfile and its config file in config folder. I know I can achieve it using a shell script however problem with that approach is all the apps have their own git repo which would be administrative overhead for me.
No, you have to add gems that you want to use in an application to the Gemfile. Because if you do not add that gem to an application's Gemfile then the application will simply not load that gem.
Another option might be to install the gem globally ion the server and require that gem in each application manually. But that still means you have to add a require 'gem_name' to all applications and this is error-prone because you lose the magic provided by bundler.
tl;dr: No, you have to add the gem to each application's Gemfile.

How can I use a gem locally without forcing it on collaborators?

I'm working on a collaborative Rails project and I'd like to make use of Thoughtbot's excellent vim-rspec gem in my own development environment without polluting the project's Gemfile (not many of the collaborators use Vim).
vim.rspec recommends it is installed as a vundle. It isn't a gem but more of a plugin.
There are instructions to install vundle on the homepage. If you install it locally outside of the rails project it won't affect your collaborators.

What is the use of Gemfile in rails?

What is the use of Gemfile in rails?
How to use Gemfile?
During your development in Rails, there will be times where you will want to provide some functionality which is required by you, but either you don't know how to do or you don't want to implement it on your own since a lot of work has been put into its development by talented developers.
These developments which you might need (user authentication, message system, asset handlers, geolocation, pagination system, linking to exterior services such as Amazon AWS, and last but not least Rails itself) are called Ruby Gems. These are ruby software packages, not necessarily relating to Rails, but since Rails is based on Ruby, 98% of the gems can be made availble to your Rails webapp code.
Lots of gems can be found in github, but its funner to search for gems via ruby-gems or ruby-toolbox
Your gemfile is a list of all gems that you want to include in the project.
It is used with bundler (also a gem) to install, update, remove and otherwise manage your used gems.
The gemfile has another purpose - you can group gems in :development, :test, :assets, :production, etc groups and Rails will know when to include the gems. For example:
group :development, :test do
gem "rspec-rails"
gem "factory_girl_rails"
gem "guard-rspec"
end
Note that on Rails 4, the assets group has been deprecated
These gems belong to development environment and the test environment since they are for testing the application. You don't need them available in the production environment (you could, but that will bloat the memory unnecessarily).
So - To use the gemfile, simply write the gem you wish to install such as
gem 'devise'
make sure to install bundler beforehand (in your console/cmd/ssh) with
$ gem install bundler
and then write in the console
bundle install
you will notice another gemfile appears! Gemfile.lock
This file, as you will see if you open it with a text reader, lists all your gems with their version and their dependencies. This will come useful when you need to know which versions of the gems you installed.
For more reading on the Gemfile - read on the bundler page
for information regarding picking a gem you could start with this
Good luck and have fun!
Ok, so whats this Gemfile.lock that got created?
Gemfile.lock, as the name suggests is a locking on all the versions of all the gems that got installed. So if Gemfile is what required to be installed, the lock file is what got installed and what version are actually required to get the app up and running.
If you don't have the gems in that specific version (as specified in Gemfile.lock) rails will complain and you will have to either install the missing gems (via bundle install) or fix any conflicts manually (I believe bundler will give you some clues on that)
Some things to know about Gemfile.lock
if you accidently delete it, it will get regenerated when you run bundle install. If you accidently delete Gemfile, you are out of luck.. You should use git :)
Heroku doesn't care about Gemfile.lock since it will reinstall all gems. So for Heroku, you must set the gem version you want, or Heroku will always install the latest version of gem, which may cause issues
Keep the Gemfile.lock in your project so you will always know what version of gems make your app work properly.
Gemfiles are configuration for Bundler, which is used to manage your application's Ruby dependencies. That website includes a lot of documentation, including the Gemfile manual page.
Explanation by analogy
You want to build a car. From scratch. You need to build: a chasis, engine, corroborator, radiator etc.
Gems allow you to utilise car parts which other people have made before
Everyone's who's ever built a car has needed the same things.
You needn't reinvent the wheel. Why make your own engine etc when you can get it straight off the shelf? What if you could get one of the best engines around, created by the most talented engineers in the world, without lifting a finger? Are you gonna spend a year trying to make your own?
So basically rather than make everything yourself, you write down a shopping list of all the parts you need:
Rolls Royce Engine
AutoLive seatbelts
Michellin tyres.
PIAA Night headlights
etc etc.
That my friend, is basically your gem file!
Your system can have lots of gems ... thus can have multiple versions of same gem.
A Gemfile specifies the list of gems with their versions that shall be used/loaded/(install if not present) whenever you run your rails application. or anything with bundle exec . .
Firstly, what is a gem?
According to Wikipedia:
RubyGems is a package manager for the Ruby programming language that
provides a standard format for distributing Ruby programs and
libraries
Gemfile
A Gemfile is a file we create which is used for describing gem
dependencies for Ruby programs
Now, in very very simple words:
Gem can be thought of as a library which you can use in your code.
Example: faker gem
Your code can use the functionality of faker gem to produce fake data.
Now you can list all the gems that your project requires in the gemfile.
When you do a bundle install, all the gems in your gemfile are installed for you.

When to Add to Gemfile and when to just install via CLI

I'm just getting started with rails and I'm a little confused reading through different documentation as to when you should add the gem to your gemfile and when you should just "gem install XXX"
For example, when installing rspec and guard-rspec. I see that some folks will:
gem install rb-fsevent
and some people put it in their gemfile and bundle.
Which is the right way and how do you know which to choose? Thanks!
The Gemfile records and manages all the dependencies for the application. When you list gems in the Gemfile, bundler sorts out any version conflicts and makes sure that the correct version of the gems are used with your application.
When you set up the application in a new environment (such as when your colleagues pull your changes from version control or when you deploy to a production web server), Bundler can use the gem file to ensure that the environment is set-up exactly as you had it in development.
So, anything on which your application depends (any code you call from your application for example), needs to be in the Gemfile. This includes libraries that you use for testing (although they can be excluded from the production environment).
Gems that are not dependancies of your application don't need to go in the Gemfile. An example would be guard which is more of a development tool than an application dependancy. You can install those with the gem command.
Typically though, most things you're going to want to install probably need to be in the Gemfile.
It doesn't matter if you install it with the gem command however. You can still put it in your Gemfile afterwards and Bundler will work out what to do.
All gems you will use in your application you should put into Gemfile.
All gems that will be just serving your application you'd better keep out of Gemfile.
For example. You need paperclip and mysql2 gems to store pictures and data, so put them into Gemfile. And you need magic_encoding gem to do some helpful stuff. But as far you are creating it straight from console, you don't need it in your application. Keep it separate from your app.
You use test frameworks when writing code, so put them into your Gemfile.
You use passenger gem to deploy your apps, but you never need to use it right in your code - don't put it into Gemfile.

Rails Plugin - Install as Plugin or Install As Gem

I am new to rails and have a question regarding the plugins. It seems there are two approaches you can take when using a third party plugin in a ROR App:
1) install a gem using sudo gem install GEM, and then "require" it in your rails project
2) install the plugin using script/generate plugin install PLUGIN. The plugin in code appears in your vendor directory and then you are good to go (sometimes, i could not get Devise working via this method).
Since it appears both of these methods accomplish them same thing, why should I choose one method over the other.
Thanks,
Try to install the gem version of something when you can. There are a couple of benefits you get over plugins:
You can have them enabled or disabled for specific environments
You can update them via gem update. With plugins, you'd have to manually go out and update them yourself.
They are shared system wide, so if you create a new project, you can use them without having to reinstall them if you used them in a previous project. You'd have to copy/paste plugins.
Plugins are specific to rails, but gems are not. It's possible to use a gem outside of Rails.
You can still unpack gems to your vendor directory by running rake gems:unpack. This is useful to "lock in" gems to their current version, and also makes for quicker deployment since you don't have to fetch them from a 3rd party site (which is the case if you do rake gems:install).

Resources