In our project, we ran
bundle package --all
one time, which according to documentation, remembers the "--all" option in subsequent calls. If I want to test a gem on my project by hardcoding it's path into the Gemfile such as:
gem 'blocks', :path => "/Users/hunterae/Projects/blocks",
anytime I run bundle install, all of the source code for this gem will be copied into my /vendor/cache directory. This means that if I make a change to the gem I am testing, I have to shut down my rails server and run bundle install again, whereas before "bundle package --all" was run, I used to be able to just stop and start my rails server.
My question is how do I get "bundle package" to once again only package gems and not try and cache :path gems? Where is the "--all" option remembered in bundler?
Look in .bundle/config in your project directory for a line that says BUNDLE_CACHE_ALL: true.
Delete that line to make it revert to packaging only standard gems.
In general, remembered options are stored in .bundle/config.
+1 to the answer form Tim Moore. Following is an addition to it.
You should avoid using :path in your Gemfile if possible and if working with a gem available on github. Since Bundler 1.9 you can use sth. like
bundle config local.name_of_gem /path/to/checked_out/repo
This will add an entry in ~/.bundle/config like
less ~/.bundle/config
---
BUNDLE_LOCAL__NAME_OF_GEM:
"/path/to/checked_out/repo/name_of_gem"
You can remove the config with the same command and including --delete like
bundle --delete config local.name_of_gem /path/to/checked_out/repo
This will avoid many problems and is easy to maintain.
Related
I need to make changed to the Twitter gem, so I cloned it to a local folder, then changed my bundle file like so:
gem 'twitter', :path => '~/code/twitter-ruby'
I added a new method, and ran a test that simply calls the method, to start off with. But I get an error of undefined method. In other words, it hasn't detected my changes. I tried commenting out a whole file, ran my other tests and those all worked, as though the file were still there.
In my project I'm still importing as require 'twitter'.
I've tried running bundle update twitter, I've tried removing it from the bundle, I've tried increasing the version number (which it does detect, and updates to the most recent version), I've tried committing my changes to GIT. Nothing seems to work - I just keep getting the same undefined method error. Any ideas?
EDIT: my Gemfile.lock:
PATH
remote: /Users/Andrew/code/twitter
specs:
twitter (5.15.0)
GEM
remote: https://rubygems.org/
specs:
PLATFORMS
ruby
DEPENDENCIES
twitter!
BUNDLED WITH
1.12.4
My issue was that I was using bundle to install the gems, but I wasn't using bundle exec to run my application. It became clear after running the uninstall suggestion and the require my_lib line starting to fail inside irb. bundle exec irb allowed it to work using the gem path defined in the Gemfile.
try this out:
First uninstall the twitter gem, by doing gem uninstall twitter, then do bundle install
Try giving the branch name too.
gem 'twitter', path: <absolute-path-to-your-local-twitter-repo>, branch: <branch-name>
EDIT
e.g. path as "/Users/me/path/to/repo"
And run
bundle update twitter
Then restart server, if running as a web application.
I'm running bundler v1.3.0.pre.2 and trying to get bundler to bundle a local git repository holding a gem, into a rails app.
Gemfile :
gem 'mygem', :github => 'myrepo/mygem', :branch => 'develop'
Config :
bundle config local.mygem /path/to/local/git/repo
Bundle install throws the error :
Local override for mygem at /path/to/local/git/repo is using branch
develop but Gemfile specifies develop
Is this a bug ? I see that the branch names are exactly the same. What could be wrong ? Got the same error for Bundler v1.2.3 as well
You can use a local gem and even the branch you are working on like this
gem 'rspec-rails', path: '~/forks/rspec-rails', branch: 'feature-branch'
Just change github to path, Then
bundle install
Also as far as bundler config goes, although it is in the docs, I have never needed to change the local config like you did above.
With this method I have never needed to remove Gemfile.lock, it just picks up the changes to your local repo.
Although I don't recommend it, you could disable the branch checking feature used by bundler to make sure you are using the correct branch when developing
bundle config disable_local_branch_check true
If you just need to point to a branch within a local repository you're using like a gem, in gemfile:
gem 'gem-name', :path=> 'relative/path/to/directory'
Then create bundler configuration for that "gem" before bundle-ing
(Keep in mind the repository name may be different than the gem's name, although this is not the norm).
bundle config local.repository-name relative/path/to/directory
Magically, whatever branch is currently checked out locally will be active when you start a local server. You'll likely need to restart your server if you need to make changes or change branches (unless you have some type of automatic reloading feature).
One gotcha is when a configuration setting is already established (let's say via the mechanism above), and you need to use/reference a remote git gem - you don't need bundler configuration to use a remote git gem (if you have an active configuration, you'll get the local override error).
Check to make sure you don't have local settings for given gem:
bundle config local.gem-name
If you do, remove configuration for that gem:
bundle config --delete local.gem-name
Then point to remote repo and branch, in gemfile:
gem 'gem-name', :path => 'https://github.com/reponame.git', :branch => 'branch_name'
More information:
Git Gems: http://bundler.io/v1.7/git.html
"bundle config": http://bundler.io/v1.7/man/bundle-config.1.html
This GitHub issue suggests that the workaround may be to remove Gemfile.lock and do bundle install again.
The branch you reference in your Gemfile needs to be the same as you have checked out in the local repository. Note that after you commit in the local repository you will need to run bundle install on your main application so that it rebuilds the Gemfile.lock to include the new revision hash and commit it. I recommend using the gem below as it automates this process for you and also aids in other scenarios. See the gem page for exact detail.
https://github.com/EPI-USE-Labs/git-bundle
Full detail of what happens:
When you use a git repository in your gemfile you can use bundle local overrides for development which will store revision hashes in your Gemfile.lock. On production these exact revision hashes will be checked out when it runs bundle install.
Gemfile:
gem 'example', git: 'https://github.com/your_name/example.git', branch: :master
Bundle config shell command:
bundle config local.example /path/to/local/git/repository
Gemfile.lock (auto generated):
GIT
remote: https://github.com/your_name/example.git
revision: b9270e61abb89e1ff77fb8cfacb463e4d04388ad
branch: master
I've forked a gem, and in trying to change it, decided to change the the gemfile from my git repository (which had been updating fine):
gem 'bootstrap-wysihtml5-rails', :git => 'git://github.com/Asherlc/bootstrap-wysihtml5-rails.git'
to the local directory (just the cloned git repository):
gem 'bootstrap-wysihtml5-rails', :path => '/Users/ashercohen/Documents/bootstrap-wysihtml5-rails'
Upon running either bundle update or bundle install, it shows the correct version number (updated since switching gem sources) in the readout. However, none of the files in the /vendor/assetspath seem to be getting updated in my Rails app. Is there some kind of caching thing I need to clear out?
I don't have a /vendor/cache file in my Rails app, and I'm confident that since the gem version is updating correctly in the bundler readout that the path is correct.
Is there some step I'm missing here?
Turns out Chrome was just aggressively caching the JS.
I created a custom gem called pdf2html. The gem file is pdf2html-0.1.gem
I placed this file in the vendor directory of rails 3 project.
My Gemfile entry for this gems reads as follows
gem 'pdf2html', '0.1' , :path => 'vendor'
When I run the bundle install command I get the following message regarding this gem
* pdf2html at `vendor` will not be cached.
I tried doing a bundle show on this gem it tells me that it is installed in the vendor directory.
Now when I do a rails console and try to do a require 'pdf2html' I get a "No such file to load error"/
Can someone tell me what I am doing wrong
Thanks
Paul
I thought the proper way to declare gems was to specify the full path, not the base path, as in:
gem 'pdf2html', '0.1', :path => 'vendor/pdf2html'
The reason it doesn't error out sooner is that the path vendor/ actually exists so there's no immediate problem. It's only when you try to require vendor/pdf2html.rb, which is missing, that there's an issue raised.
I pushed the gem and associated files over to github and then installed it from there using the Gemfile/ bundle install. Now its working fine. I could not figure out how to use the local gem file
Let's say in a Rails app you have some gems that you use in your app (we'll call them "primary gems") and you have vendored them for portability.
Let's say that those "primary gems" also require gems of their own - we'll call these "secondary gems".
When you are setting up your environment.rb, you have to say:
config.gem 'primary-gem'
for any of the gems you are using directly.
But, do you also need to say . . .
config.gem 'secondary-gem'
even if you are not using that gem explicitly in your app?
Or is it simply enough to include the gem in your vendor/gems directory for it to get picked up by your app?
At deploy time rails knows about your dependencies, so if you want to freeze your gems then you can run
rake gems:unpack:dependencies
to freeze them into the vendor directory.
At runtime however it's the gems job to load it's dependencies, and usually the gems do this, so a config.gem 'primary' should work.
No, you don't or at least you shouldn't. Each GEM specification should include it's own list of dependencies. When primary gem is installed, RubyGems automatically will install each gem dependency on cascade.
In other words, if A requires B that requires C+D, you only need to write
config.gem 'A'
When the command
gem install A
is run, RubyGems will resolve all the dependencies and install them.
You can view all A dependencies running (from a Rails project)
rake gems
Sometimes, a GEM author may forget to include some GEM dependencies in the specification. In this case you should specify them in your environment.rb to force the application to install them. Off course, it's also a good idea to contact the GEM maintainer so that it can fix the problem.