I am creating a gem, which has a dependency on another published gem.
In my_gem.gemspec, I have added the dependency to the other gem:
gem.add_dependency "other_gem", "~> 1.0.0"
Now, I found a feature that can be tweaked in other_gem, so I forked the repository, made my changes and committed it to the fork (It has not been pulled into the original repository).
My question is how do I tell my_gem to lookup other_gem locally? The below code snippet is not valid, as :path is not an option in add_dependency call, as mentioned in Gem Specification Reference:
gem.add_dependency "other_gem", "~> 1.0.0", :path => '/path/to/local/other_gem
Locally it's much easier: while you're doing development, you can include:
gem "other_gem", :path => '/path/to/local/other_gem'
or
gem "other_gem", :git => "git#github.com:/your_github/other_gem.git"
in your gemfile, as this should override the gemspec
Locally it is not likely possible to give path to the gem dependency because if you are doing so that means you are imposing a restriction to the self made gem that it is depending locally to any other gem.
This is not desirable as when you will upload it, this will not work. So the solution is to add remote dependency in your own plugin's gemspec.
See my SO post for the same here.
I would create and install a new other_gem-version, e.g. '1.0.0.Subash_fix' and use it as
gem.add_dependency "other_gem", "= 1.0.0.Subash_fix"
When there is a new official version of the gem with your patch you switch back to the official one:
gem.add_dependency "other_gem", "~> 1.0.1"
Related
I am trying to build the docrails in my system. When I clone the repo and do bundle install as the guides say.
I get the following error
You passed :github as an option for gem 'rails/active_record_deprecated_finders'
, but it is invalid.
Entry in gemfile looks like this:
gem 'rails/active_record_deprecated_finders', github: 'rails/active_record_deprecated_finders'
To avoid that what I am doing is commenting the rest of the line like this:
gem 'rails/active_record_deprecated_finders'#, github: 'rails/active_record_deprecated_finders'
Then it foregoes that and the next problem arrives with the error message saying:
Could not find gem 'active_record_deprecated_finders (>= 0) x86-mingw32' in any
of the gem sources listed in your Gemfile.
Environment specs:
Bundler version 1.0.21
Rails 3.2.3
Win7 64bit
Question
I dont know why its looking for x86 when my System is 64bit.Is there any work around for this? or its a bug?
If gem file couldn't accept github: as parameter why is it there in the first place?
Please let me know if there are any workarounds to this problem
The :github option is just shorthand for a longer :git option:
gem :foo, :github => 'rails/foo'
Is just short for
gem :foo, :git => 'git://github.com/rails/foo.git'
This is new in bundler 1.1 which is why it doesn't work on your setup. You could rewrite the gemfile but it would probably be easier to update bundler. In addition bundler 1.1 is a lot faster than 1.0
I'm using 'rails3-jquery-autocomplete' gem, but it doesn't have multi column search, but there is a fork that does it ( more details at: https://github.com/crowdint/rails3-jquery-autocomplete/pull/95).
Now I need to deploy to Heroku but it will install the official gem. How can I edit it? Or if it's not possible, how can I import a gem to the application?
Thanks.
you can use the fork by specifying the :git path in your Gemfile declaration
something like
gem "_GEM_NAME_", :git => "git://git/repository.git"
your other option would be to just vendor the gem inside your into a directory like vendor/gems/_gem_name and then you could use the :path option as well
gem "_GEM_NAME_", :path => "vendor/gems/_gem_name"
I have a git submodule of git://github.com/rails/rails in vendor/rails of my Rails 3 app. This is where an unpacked/vendorized Rails would go prior to 3.0.
How do I instruct my Gemfile that vendor/rails is the correct location, and not my system-wide rails install?
So, some people have noted that you can do simply:
gem 'rails', :path => "vendor/rails"
You can also include a version number, e.g.,
gem 'rails', '3.0.3', :path => "vendor/rails"
Both of these depend on what you actually have in vendor/rails. For example, if I do git checkout v3.0.3 in vendor/rails, both of these will work fine on their own (3.0.3 is the current).
But if I use a beta instead, I seem to need to add some additional dependencies:
gem 'rails', :path => "vendor/rails"
gem 'arel', :git => 'git://github.com/rails/arel.git'
gem 'rack', :git => 'git://github.com/rack/rack.git'
I could also extract these into vendor as git submodules, I suppose, and again use :path.
Do be aware that rack comes from rack/rack on github, not rails/rack. The latter is a fork and hasn't been updated since 2009. I made this mistake and spent hours fixing it.
If you've got older versions of rails installed on your machine, you may also need to take care to use script/rails instead of the rails command.
Isn't it just gem 'rails', '3.0.3', :path => "vendor/rails" in your Gemfile?
Use this line in your Gemfile:
gem 'rails', :path => "vendor/rails"
I am trying to use this forked version of the searchlogic gem. In my gemfile, I have
gem "searchlogic", :git => "http://github.com/railsdog/searchlogic.git"
when I do bundle install, I get this error:
Could not find gem 'searchlogic (>= 0, runtime)' in http://github.com/railsdog/searchlogic.git (at master).
Source does not contain any versions of 'searchlogic (>= 0, runtime)'
What is causing this error? Thanks for reading.
It's because your fork not define searchlogic gem by rd_searchlogic gem. So use in your Gemfile :
gem "rd_searchlogic",
:git => "rd_searchlogic.gemspec",
:require => "searchlogic"
Use:
gem 'rd_searchlogic', :git => 'https://github.com/railsdog/searchlogic.git', :require => 'searchlogic'
The .gemspec of your fork might contain a different name to that of the gem on RubyGems, for example when I forked active_merchant on GitHub their .gemspec file had:
s.name = 'activemerchant'
but the gem is defined as active_merchant on RubyGems so I changed my Gemfile from:
gem "active_merchant", git: "https://github.com/adamwaite/active_merchant.git", require: "active_merchant"
to:
gem "activemerchant", git: "https://github.com/adamwaite/active_merchant.git", require: "active_merchant"
note the lack of _.
All worked perfectly after that. This may be an obscure case, but hope it helps someone!
It doesn't look like that gem has been upgraded for Rails3. From the issues listed in Github, it seems that searchlogic is heavily dependent on ActiveRecord2 and may not be easily upgraded for Rails 3. It may be worth looking into an alternative.
Will searchlogic work with Rails 3?
http://github.com/binarylogic/searchlogic/issues/issue/65
I am working on a rails gem that has dependency on the following
gem 'authlogic', :git => 'git://github.com/odorcicd/authlogic.git', :branch => 'rails3'
How can I add this in the gem spec as a dependency? Specifically I need to specifiy the path and branch in the dependency.
You definitely want to use Bundler then. You would put exactly what you have into the Gemfile file. Go checkout the link to Bundler I left below.
-- older info --
For jeweler you would add something like this:
gem.add_dependency 'authlogic', '> 1.0', '<= 2.0'
But you might be better off using Bundler. It's not just for rails: http://gembundler.com/
You need generate the gem. Publish it and after use this gem deploy.