1

I'm using the Xeroizer gem and want to monkey patch one of the pull requests which adds functionality I need.

There are four commits on that request, and for some of them it involves patching a class inside a module. Is it possible to do this without having to fork the gem and forever maintain that (or until such a time as this pull request is merged)?

I've found this stackoverflow question which is similar but doesn't quite cover the same scenario, and this post which deals with patching modules, but my attempts so far have ended up either breaking the gem or just not working.

Community
  • 1
  • 1
bdx
  • 3,316
  • 4
  • 32
  • 65
  • Did my answer help at all? – C dot StrifeVII Nov 13 '16 at 21:06
  • I found an alternative solution to my problem that didn't involve monkeypatching so I never tried your suggestion as the base problem is no longer relevant. Your answer is what I was considering originally but as the API gets fairly frequent updates, I needed a solution that wouldn't exclude future patches from the base gem. – bdx Nov 15 '16 at 19:43
  • Would you mind posting your solution to help the community – C dot StrifeVII Nov 15 '16 at 19:55
  • My solution reworked the architecture of the related module that was using the gem that needed to be monkeypatched and isn't in any way an answer to my question, so it's not one I could post to help others. – bdx Nov 16 '16 at 04:34

1 Answers1

0

Ok this is what you can do

  1. Clone with the command git clone https://github.com/waynerobinson/xeroizer.git the repo somewhere on your system (lets say ~/Xeroizer for ease of example)
  2. Then navigate to the repo in this case ~/Xeroizer
  3. The switch to the branch in question with the command git checkout add-balances-to-contact
  4. Then navigate to your rails project
  5. In your editor open up you gem file
  6. Once in your gem file locate the line where you included the Xeroizer gem it should look something like gem 'xeroizer'
  7. Replace that line in your gem file with gem "xeroizer", :path => "~/Xeroizer"
  8. Then save your gem file and close your editor
  9. Then run bundle

That should give you the the version of the gem that you want. Alternatively you can swap out gem file command in step 7. from the above list with this command

gem "xeroizer", :git => "git@github.com:waynerobinson/xeroizer.git", :branch => "add-balances-to-contact"

throw it in your gem file and just run bundle

As to your question about having to maintain this forever the answer is currenly no because this branch was merge a few weeks ago, but otherwise would have to maintain it to some degree.


C dot StrifeVII
  • 1,885
  • 1
  • 16
  • 21
  • You may be able to use git's submodule feature to get your changes in, otherwise you could keep the trees separate and use a magic script to do the patch for you. This adds the opportunity to do some extra checking (do all of these files exist?..). – ti7 Nov 13 '16 at 16:54