Bring Rails gem locally - ruby-on-rails

I am working on a Rails 4 application and one of the requirements is to have all of the Gems that normally go into the Gemfile brought in locally to the machine for use. This includes Rails and after looking at many google search results I am not able to find anyone talking about using the Rails gem locally on a Rails project.
My train of thought here is to clone the rails project from Github locally and then using the bundler config path to target that directory for rails, but I am not sure how well will that solution work or even if it will work.
I will appreciate any input here or if anyone has experience with this situation I will appreciate any insight.

The bundle install does that ?
If you want to install any gem to your project go to the project root on cmd
$ gem install gemname
Doing that you locally installed the gem afterwards you want to make sure its loaded to your project so you can run
$ bundle install
And simply like that your gem is installed. Hope that helps

If you have your project on github, then you can clone it using command.
git clone github-repository-url
And then from that project directory, run command
bundle install --path vendor
It will install all your rubygems into vendor directory.

Related

Ruby on rails 5; How to stop installing gem related files when I bundle install

I was making a chat app with ruby on rails 5.
I tried to implement image sending function in my app.
I followed the instruction of the below blog.(sorry in Japanese)
http://yamakichi.hatenablog.com/entry/2017/01/18/232856
1) bundleinstall below gems
gem "carrierwave"
gem "piet"
gem "mini_magick"
2) Create uploader
But it didn't work.
I removed gem "piet" by bundle upload after I deleted it.
At this moment, I realized that about 8000 unknown files were installed.
Below are examples of the file names installed.
vendor/bundle/ruby/2.3.0/bin/rake
vendor/bundle/ruby/2.3.0/cache/concurrent-ruby-1.0.5.gem
vendor/bundle/ruby/2.3.0/gems/concurrent-ruby-1.0.5/lib/concurrent/hash.rb
....
All the files start with "vendor/bundle/ruby/2.3.0".
If I delete this "vendor/bundle/ruby/2.3.0" file, I can remove every unnecessary files.
But next, I couldn't turn on local server.
It said,
"Could not find rake-12.1.0 in any of the sources"
"Run bundle install to install missing gems."
And if I bundleinstall, this 8000 file were installed again.
How can I avoid this problem?
The gem piet may be a dependency of another gem in your Rails project. When in doubt you can delete your copy of Gemfile.lock and run bundle again. It will auto-generate a new copy with the correct dependencies.
If you're working on a Rails project, it's totally normal for ~8,000 files to be installed since Rails itself relies on quite a few gems.
One way to cut down on the number of files installed by bundler is to skip the documentation within each gem. That can be accomplished by adding this to your local ~/.gemrc file
gem: --no-document

gem development (not load other Gemfile)

I've an issue with gem file development, for example I'm creating a gem with executable command.
It all works well, I can run command, BUT I've issue that if I'm trying to run command inside another project folder it's USING Gemfile from this second project.
Can I somehow disable it?
I want only to use Gemfile (and .gemspec) from my gem, and not with folder where it was executed.
I have a gem github.com/igorkasyanchuk/rails_db (version in master branch is not released yet, so you need to build it locally), gem build ..., then gem install ..., and then go to your project dir and run "railsdb". When you run it, it's trying to load gems from local folder Gemfile.
Thanks
Igor
If you are using the rubygems-bundler gem, executing commands provided by a gem will load the bundle of your current directory. You can prohibit this from happening for a particular gem providing commands in various ways. One way:
export NOEXEC_EXCLUDE=my_gem_command
See https://github.com/rvm/rubygems-bundler for more information about rubygems-bundler.

How to build a gem from rails source code?

I want to make a gem from rails source code and install the gem.
After clone the master repository of rails, I tried as follow.
$>gem build rails.gemspec
$>gem install rails-4.2.0.alpha.gem
It did not work. I also tried $>rake install which did not work either.
Looking forward your help!
There is a script in the root directory which builds from source and installs the gems. It's called install.rb. You can use it by running the following:
ruby install.rb 4.2.0.alpha
Note: At the time of writing this the arel gem needs to be built from source and installed separately before running the install script above. This is because the version constraints in rails are requiring a version of arel which has not yet been released onto rubygems.org.

RVM why don't gems install to locally to project folder?

So here's my problem:
I have a project and I am trying to install Gems locally to that project. For example if I install devise from the Gemfile and then run a bundle install it won't put any of the controllers in the controllers directory of the project. Instead I have to hunt through the RVM directories to get that particular gem's controllers, copy them to my project and then start writing my project from there.
Any suggestions?
I think the comment above answered your question - when you add a gem like Devise to your app, it doesn't generally drop code directly into your application. Sometimes it provides a generator which will install some parts of it, but mostly it alters config files so that the code in the gem gets pulled into your app when it starts.
You can ask bundler to install gems in the "vendor" subdirectory of your app, instead of in the main RVM/Ruby location, with the --path option. But you usually only want to do that for production deployment, not development.

Using Hunspell With Heroku

I'm building a Rails app that uses Hunspell and the hunspell-ffi gem so that Ruby can interface with it. I'm deploying the app to heroku, but unfortunately it needs Hunspell to be installed on the server in order for the gem to work.
Is there any way for me to install Hunspell on Heroku? Or am I going to have to migrate to EC2?
Thanks in advance :)
You need to build the required Hunspell library and include it in your Heroku project directly.
Heroku runs on 64-bit Ubuntu therefore the binary has to be compiled under that system. The best approach is to simply use Heroku's Vulcan build server to compile on a Heroku instance.
Compiling for Heroku
gem install vulcan
vulcan create vulcan-compile-me last argument is your own app name.
Download Hunspell source
Extract
vulcan build -v -s ./hunspell-1.3.2 Tells Vulcan to build it and downloads the finished product automatically to /tmp/hunspell..
The build server requires the cloudant add-on, this is installed automatically but you have to make sure to have a verified (credit card added) Heroku account. If you get errors in step six of no build output then do heroku addons:add cloudant --app vulcan-compile-me
Adding to Your Project
Extract the Heroku Vulcan build tar from /tmp
Copy the entire lib folder to vendor/hunspell in your project root directory
Tell Heroku where to look for libraries: heroku config:add LD_LIBRARY_PATH=vendor/hunspell/lib.
Install Dictionaries
Download some dictionaries from Open Office and add them to your project. A good location is a folder called dictionaries at root level. This path is then referenced when initializing Hunspell in Ruby.
http://extensions.services.openoffice.org/dictionary
ftp://sunsite.informatik.rwth-aachen.de/pub/mirror/OpenOffice/contrib/
Using
Install your favorite Hunspell gem, I use hunspell-ffi. There is a newer gem for Hunspell but I prefer the previous FFI gem. To use initialize the Hunspell object with your dictionaries folder path and language (language match the dictionary file name).
dict = Hunspell.new("dictionaries", "en_US")
if dict.check('caribean') == false
suggestions = dict.suggest('caribean')
if (suggestions.size)
correction = suggestions.first # returns 'caribbean'
end
end
Vendoring for More Complex Projects
You can also vendor the library into your project by putting the tar built by the Vulcan server in the first step into a public accessible server such as Google Storage and then changing the Heroku build pack to download the tar on each instance startup.
heroku config:set BUILDPACK_URL=https://github.com/peterkeen/heroku-buildpack-vendorbinaries.git
The vendor build pack looks for a .vendor_urls file at the root level with HTTP links to the tar balls to install (needs to end in a new line to work).
http://commondatastorage.googleapis.com/developer.you.com/hunspell-heroku-1.3.tgz
Vendoring unpacks the tar into the root folder so the lib path for the Heroku settings would then just be "lib". heroku config:add LD_LIBRARY_PATH=lib
Unless I am mistaken or something has changed (I cannot find any evidence of this), you cannot install external native libraries on Heroku. If the library is not already installed (this is the case, I think, for ImageMagick, and perhaps others), you will not be able to use the gem.
Checkout this url: http://gems-summary.heroku.com/2011-07-19
It's freaking amazing how much support Heroku has for the gem community. So all you need to to is add the gem to your bundle since Hunspell is on rubygems, bundle install, and then deploy.
Gemfile
source 'http://rubygems.org'
gem 'rails', '3.0.5'
gem 'hunspell'
Then add to git:
git add .
git commit -m 'added hunspell'
Then bundle:
bundle
And deploy:
git push heroku
With Bundler, you should be able to install any gem. According to http://devcenter.heroku.com/articles/how-do-i-install-gems-for-my-app, "Almost any gem - even those with native dependencies - can be installed using Bundler. If there’s a specific gem that won’t install on Heroku, please submit a support ticket."
AFAIK, when your app is spun up, gems in the Gemfile are installed on-the-fly to the server your app is spun up to.
The Aspen stack has pre-installed gems, but you still should be able to add gems not pre-installed.
The bamboo stack has no pre-installed gems, so all gem dependencies must be declared explicitly. I believe that is the same for the Celadon stack.

Categories

Resources