Recently I started using a gem called blackbook. The gem has a few issues that I would like to fix. I cloned the git repo and installed the gem locally, hoping I could mess with the source code. When I edit the source code nothing happens, so now I am thinking that I must rebuild the gem every time I make a change.
My question is this:
Should I be able to edit the source code of the gem and see results immediately, or should I use the source code as a plugin to my rails app, and then rebuild the gem only when I have made significant progress?
Thank you,
Tony
I use this rake task to make keeping my gem up to date while working on it. It uses a version number stored in a file at the root named 'VERSION'
desc "Build and install homer gem"
task :update do
version = File.open('VERSION') { |f| f.read }.to_s
`gem build homer.gemspec`
`gem install ./homer-#{version}.gem`
end
and in the gem spec:
s.version = File.open('VERSION') { |f| f.read }.to_s
You can mess with the source code of the installed gem to change the behavior of what you have installed. But unless you are playing path games this won't affect the gem itself even if you rebuild.
What I generally do is this:
Set up a development area where I can make changes & test them (e.g. run unit tests, spec, etc.)
Do most of my work there
When I've got something I like, rebuild the gem and try a test install
If that works to my satisfaction, push it.
Also, if you are using git hub they should automatically rebuild the gem for you every time you push a commit with an updated gemspec (e.g., you've changed the version number).
Related
I'm curious if there is some comfortable way to use some gem locally but not pushing it to a public repository.
For example, let's assume that project I'm working on is not using in development gem likebetter_errors, but it may be very useful for me.
I know I could add it to my Gemfile and just not include it in a commit, but then I could forget about it and push it someday. Also keeping it in mind all the time may be frustrating.
I just wonder is there some nice way to have it automatically included in the local copy and preventing from pushing.
You could add an initializer like this to your Rails app:
# in config/initializers/local_gems.rb
%q[better_errors binding_of_caller].each do |gem|
require(gem) rescue puts("Gem not installed: #{gem}")
end
But this only loads the gem when it was installed before and that means you have to install it manually and cannot use bundler.
This is my first question on StackOverflow. Please bear with me if I am doing it wrong.
I am working on a ruby on rails application and had to change the source code of a gem I am using in
/Users/username/.rvm/gems/ruby-2.0.0-p353/gems/gemname-4.1.0.
This works well and I make a fork of the gem on github, applied the changes I made, pushed, and change my gemfile line from
gem 'gemname'
to
gem 'gemname',:git=>"git#github.com:/name/gemname.git"
I run bundle install again and now the changes made are not applied to my application anymore.
When I do bundle show 'gemname' I saw the gem is install in
/Users/username/.rvm/gems/ruby-2.0.0-p353/bundler/gems/gemname-a0ed76fc98e2
I am not an expert on how bundle and github works. If anymore could explain how they work and what I should do to use my own forked version of the gem in my application, it would be very help!
Thanks in advance!
you could also write:
gem 'gemname', 'git://github.com/name/gem_name.git
or:
gem 'gemname', github: 'name/gem_name'
also be sure that you have your changes in master, and restarted your server after bundle
I ended up doing,
gem 'gemname',:git => "git#github.com:/myname/gemname.git", :branch => '1.1'
and it works fine now.
I think the problem is that I need to specify the branch 1.1 which is my branch, otherwise it uses the master's branch which my changes are not applied.
I'm starting a project where I will work with the base Gollum wiki gem, and add some features to it. I was wondering what is the best way to do this.
Do I need to build and install the gem everytime I need to test it? Is there a way to edit the source code of the gem and test it on-the-fly?
I'm only a beginner at this, so sorry if this is a silly question!
Clone the git into your userspace;
Checkout the source code somewhere into your Projects directory;
Put in your main projects Gemfile the following:
(instead of :git => ...)
# V VERSION IS HERE
gem 'gollum', '~> XXX', :path => '/home/Projects/gollum'
Run bundle update in your main project directory each time you changed smth in gollum. Don’t forget to commit changes to github into your gollum fork and point gem instruction to it into Gemfile before uploading.
Hope it helps.
There a couple different things you can do in this situation if you are using bundler. First, you could simply edit the gem locally. Running bundle show gollum will show you the directory in which the gem is installed and you can simply edit it and the changes will appear in your application. In the end, you will need to either fork the gem and use your own version in your Gemfile. Documentation on using a custom git repository can be found here: http://bundler.io/git.html
Also in that documentation is how to set up a local git repository. If you plan on having a separate gollum repository and pushing it our, you will probably want to work with a local copy. Rather than simply pointing to a separate directory on the filesystem, it is useful to use bundler's "Local Git Repos" feature, which is also documented in the link above.
Either way, once you are ready to push out your code, you will want to point your code to the remote repository so you can actually deploy it.
I am trying to push into rubygems.orge a simple gem following this tutorial. Basically I am using bundler and I have write a simple Hello World class. Then, I try to push the gem as follows:
bundle gem my_first_gem
gem build my_first_gem-0.0.1.gem
and I get:
Signed in.
Pushing gem to https://rubygems.org...
Repushing of gem versions is not allowed.
Please use `gem yank` to remove bad gem releases.
So, I have checked and there is already a gem with such name. So, is there an easy way to rename the gem I have including changing the gem name in all generate by bulder files:
or if I should rename the files by hand, could you tell which are the critical ones?
Instead of renaming files by hand. As it is just a tutorial gem, I would suggest you to create a new gem with
bundle gem gotqn_first_gem
and just move your HelloWorld class in lib. And follow the rest of the commands suggested in Railscasts.
Don't forget that after renaming you need to call git add -A to update your files list.
The reason for that is because (unless that you have changed) your my_first_gem.gemspec have a line like that:
spec.files = `git ls-files -z`.split("\x0")
So, when you call gem build my_first_gem-0.0.1.gem, the above command will search for your older files and ignore the renamed ones.
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.