I am working on a project written in Ruby, which depends on another module using require modulename. I can change the required module to add the features I need, but I don't want to modify my installed version. I've downloaded the module from git, but I don't know how to point my project to this local version.
Assuming the required module is a gem, you can use the path: option in Gemfile to define a local version of a gem. So in Gemfile:
gem 'modulename', path: 'relative/path/to/modulename'
However, remember to remove the path: option before committing any changes to your git repository as you don't want that going into production.
Related
We use Rails for the majority of our web projects and in a lot of cases we share code we have as dependancies such as our API as Gems. We also have some projects which are similar in nature enough that we've built Engines and then have host applications that use these.
These are all hosted on our own servers and we share the Gems with the projects using Gem In A Box (this is because we can't upload the Gems to anywhere else due to security restrictions). During development we comment out the lines to reference either a specific version on our server or our local version if we are developing within the Gem itself.
So for example:
# version on the server
gem 'our_gem', '1.1.0', source: 'https://gems.domain.net'
# local version
gem 'our_gem', path: '../our_gem'
What happens is that when we do a build on our CI server we then have a script that reads through the Gemfile and finds any gems that have our server as the source and then vendorize them and reference them as the vendored path.
For example:
# this
gem 'our_gem', '1.1.0', source: 'https://gems.domain.net'
# becomes this
gem 'our_gem', path: 'vendor/gems/our_gem-1.1.0'
However the problem we have encountered is that when we are in development and we may have several features or bugs we want to push to our QA team to start testing it means we have to bump the version each time so we can reference it in our Gemfile's as a dependancy. We can't reference the branch due to the Git repository not accessible to our build setup and some other restrictions.
How do teams usually handle in-development dependancies that don't have a version yet? We've thought about having a development version of Gem In A Box and then not passing a version to it in our Gemfile...
# shared dev version of gem on our dev gem server
gem 'our_gem', source: 'https://dev.gems.domain.net'
But the problem here is that we still need to up the version every time in order to push to the Gem Server. Is there a standard way to push a package to a Package Manager whereby the version is always the same (or better yet is version-less but hosted by the manager)?
We also have the same issue with NPM (we run a local version of Vedaccio).
I've been using a Ruby package which I installed as a gem. Now I'd like to modify the code, to try my hand at fixing bugs/adding features. I can download the source for the package from GitHub, however, I'm not sure what to do next.
Is there an easy way I can replace a particular gem with code from a local source directory? Ideally, the process would be simple enough that I'd be able to continuously update as I modify the code.
Also, this package is used as a dependency for other gems, and ideally the other packages which use this gem would then use the updated version. (As the program I'm ultimately running is from one of those other gems.) Is there a way to do the install without also installing those other packages from source?
(This would be on Linux, if it makes things easier.)
Assuming your using bundler you can set this in your Gemfile. If your not sure your using bundler look in the root of your project. There should be one file called Gemfile with no extension. The presence of this file will generally indicate that the project's author is using bundler. All changes described below should be made inside that file.
The :path and :git keys in the gem hashmap can be used to point rubygems to different locations. When I am using :path I will have two different ruby projects. The first project is the active project. The project that I am currently working on. This project requires the gem in question that I need to update. The second project will the the checked out source code of the gem I wish to change. With these two projects setup I can edit the Gemfile of the first project and point it at the second project. This is done using :path.
# The Gemfile of the first project
gem 'the_gem_in_question', :path => '/the/path/to/the/second/project'
There are two ways to modify these files and have the changes show up.
One is using the Gemfile to define a path. For example if you wanted the redis gem locally, you can git clone git#github.com:redis/redis-rb.git then as Stewart pointed above, put it into your Gemfile this line gem 'redis', :path => './pathtoredis/redis' instead of gem 'redis'
Another way, which is a little quicker but harder to track changes and stuff is to just gem open redis to open it in a text editor.
TL;TR
We have two projects (minitest project, and a page objects project). The Minitest project uses the page object project. When Jenkins runs the tests, we use a remote git path to the page objects project. When we run it locally we change the gem file in the minitest project to use a local path\or local git repo. This results in us needing to continuously change the gem file. We don't wan't to have to do this. How can we set this up so that we don't need to keep changing the gem file?
The long version
I have two Ruby projects, which are tightly coupled. Both projects are used to support testing with Capybara. One project contains Minitest tests. The other project contains page objects. The minitest project uses the page object project. The page object project is published as a gem so that other teams can use it. Quite often we need to edit both projects at once.
I am using Bundler to manage the gems. These projects used to be in two different git repos.
The tests run in Jenkins, and when we work on them we run them locally. When the tests run in Jenkins the minitest project can reference the page objects project either as a published gem or as a remote git repo.
The problem we had with this is that we kept needing to change the gem file of the minitest project. We would change it from pointing to a remote git repo, to a checked out (local) path. Or we would point to a local git repo. In this case we would still need to update the minitest project's gem file with the local branch name. We needed to edit the gem file with either approach, then we had to remember to change this back before checking in and merging.
We then moved both projects into a single repo. Now the gem file in the minitest project only uses the relative path e.g. path => .... This means that we don't need to constantly update the gem file in the minitest project. However, now when we run bundle install or bundle update, only the gem file from the minitest project is used (at least this is what I assume is happening).
How do I use a different gem path\git repo on my dev machine to what is used in Jenkins, without continuously changing the gem file?
I would like to know what approach should I be using in this case? Can avoid making changes to the minitest project's gem file?
Consider using bundler's groups (in Gemfile):
group :project1 do
gem 'rspec'
end
group :project2 do
gem 'minitest'
end
Then specify which group to use in application.rb, for example
Bundler.require(:project1) # or :project2 depending on the project
More info here: http://bundler.io/groups.html
Not wanting to commit to e.g. .rvmrc for specifying the ruby version.
If your project is using a Gemfile you can set it there too:
ruby '1.9.3'
This is of course 'per project' and not global. Heroku uses it that way.
In the top-level directory of your project, create a file named .ruby-version containing only the version of ruby you want to use, e.g.
2.1.0
You can sometimes also specify system (known example: MacOS).
I am trying to hack through a forked gem (buildr). As such I cloned it from github and began to butcher the code. The official gem is installed on my system (under /usr/lib/ruby.../gems/buildr...). There is an executable which I need to use in my dev process - buildr.
Now I want the buildr executable and the library to point to my forked repo and not the default gem installation. This would be for this gem only. As such, the changes I make against the forked repo is usable directly for testing and so forth.
I would guess I need to load my library prior to the system gem loading. Can somebody recommend the best way to do so?
I did something similar for work when the Spreadsheet gem broke backward compatibility. I put the previous versions code in it's own module and just renamed the gem my-spreadsheet and installed that (I really wanted some of the features of the new gem but I also didn't want to rewrite all my previous code at that point).
If it's just a binary you want to override you could always do some PATH magic, setting the directory of your binary first and thus make sure you always override. But personally I'd prefer making my own copy with a new name and installing that.
you could bump the version in the gemspec for your fork. Then when you install your version of the gem, it will use your (newer) version by default.
change buildr.gemspec
#...
spec.version = '1.3.4.dev'
#...
Then
$ gem build buildr.gemspec
$ sudo gem install buildr-1.3.4.dev.gem
and it should work.