Can't load gem from local path - ruby-on-rails

I'm creating an azure wrapper for dragonfly gem and I've published it in rubygems. Now I'm loading it in the Gemfile of my rails app with:
gem 'dragonfly-azure_data_store',
git: 'https://github.com/meloncargo/dragonfly-azure_data_store.git',
branch: :master
and the gem loads, but as I'm changing it constantly, I've configured bundler to load directly from my path:
bundle config local.dragonfly-azure_data_store /home/alter/workspace/meloncargo/dragonfly-azure_data_store
and when I start the rails app, it throws:
/home/alter/.rvm/gems/ruby-2.4.2#productwatcher/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:292:in
`require': cannot load such file -- dragonfly-azure_data_store
(LoadError)
I've tried setting the gem as a path, without the bundler config:
gem 'dragonfly-azure_data_store',
path: '/home/alter/workspace/meloncargo/dragonfly-azure_data_store'
But I receive the same error. Just for the record, my local gem has the same changes as in master and any change I made locally (example: adding puts 'foo' inside def initialize of the main class), is reflected when I started the rails app, but eventually the error is raised.
Any idea what could be the problem?

I've just realized the problem has to do with I'm using require_reloader gem .
I've created an issue to see what happens with it.

Using a relative path for the argument should work
gem 'dragonfly-azure_data_store', path: '../dragonfly-azure_data_store'
And in your ruby file:
require 'dragonfly'
require 'dragonfly/azure_data_store'

Related

Cloning a gem to a local file isn't detecting my changes

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 developing a Ruby gem, how can I try it out locally with my Rails app?

I am developing a gem meant to be used with Rails projects and want to try it out locally with another Rails app of mine.
I built the gem with bundle exec rake release which put a .gem file in the /pkg directory.
Then, in my Rails app, I added the following to my gemfile
gem 'mygem', '0.1.1', path: '/Users/me/projects/mygem/ruby/pkg'
I then ran bundle install which said it installed the gem. When I do this, it removes the gem from the path. IDK where it went.
When I start the Rails app, it's like the gem isn't included at all.
Interestingly, if I add a version that doesn't even exist, it still says bundle install works fine. (Example: gem 'mygem', '0.1.2345', path: '/Users/me/projects/mygem/ruby/pkg')
What am I supposed to do to try out my Gem locally with a Rails app?
This question is different from How can I specify a local gem in my Gemfile? because I explicitly tell bundle in my Gemfile to use the local gem, with the path given, and it still doesn't work. When I run bundle install, it says
Using mygem 0.1.1 from source at /Users/me/projects/mygem/pkg
So you'd think it works right, but it still doesn't.
Interestly, if I try it with a version number that doesn't exist, like mygem 1.2.3, it still runs bundle install successfully, which is really weird and seems like a bug:
Using mygem 1.2.3 (was 0.1.1) from source at /Users/me/projects/mygem/pkg
I prefer to use the following when working on a local gem side-by-side with a Rails project:
gem 'foo',
:git => '/path/to/local/git/repo',
:branch => 'my-fancy-feature-branch'

"Cannot load such file" error when deploying Rails app to Heroku

I'm using a gem for gmail in my Rails app. My Gemfile contains:
gem 'gmail-api-ruby', :require => 'Gmail'
And in my controller, I initialize the gem with (using devise/omniauth to get the refresh_token from Google):
Gmail.client_id = ENV['CLIENT_ID']
Gmail.client_secret = ENV['CLIENT_SECRET']
Gmail.refresh_token = current_user.refresh_token
This works fine in development, but when I deploy to Heroku, I get the following error:
/app/vendor/bundle/ruby/2.2.0/gems/bundler-1.7.12/lib/bundler/runtime.rb:76:in `require': cannot load such file -- Gmail (LoadError)
I cannot figure out why. Should I be requiring the gem somewhere else in my app?
Ruby 2.2.0
Bundler: 1.8.5
Rails: 4.2.0
require is case sensitive if the underlying filesystem is case sensitive (which it is on linux, which is what underpins heroku)
Change to :require => 'gmail' instead of Gmail and you should be ok.
Just remove useless require option from your Gemfile because bundler can load classes inside of this gem without specify require option in your case.
gem 'gmail-api-ruby', '~> 0.0.10'
and run bundle install.
FYI: read section about require option here.

Local Gem Causes Heroku Push to Fail

I have a Gem on my local machine that I declare in my Gem file like this:
group :assets do
gem 'my_gem', path: "/Users/me/path/to/my_gem"
end
This works great locally, but when I push to staging on Heroku, the build fails because the gem isn't available.
Currently I'm having to comment/uncomment this gem between deploys which is a real pain.
I've also tried adding it to my development group, but this doesn't help.
Why is Heroku looking for this gem?
Bundler always needs to resolve all of the gems in your Gemfile. You shouldn't commit a Gemfile that contains a local path.
Instead, push your gem to a git repository that is reachable from Heroku and point to that in your Gemfile.
For development, you can use a local path override: http://bundler.io/v1.3/git.html#local
you can try placing the gem in vendor/gems directory, create it if it doesn't exist.then in your Gemfile do like this:
gem 'rails_multisite', path: 'vendor/gems/rails_multisite'
and make sure you run bundle update so Heroku can Pickup the changes

custom gem with rails 3. No such file to load

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

Resources