Modifying a gem, best way to deploy

For a project I used the gem 'event_calendar'. However, there were a
couple things I had to manually change within the gem source to suit my
needs.

How would I go about to deploy this in production 'the rails way'? Right
now I have just replaced the sourcecode of the gem installed on my
production environment. This is ofcourse unmanageble over time if I ever
have to reinstall (bundle install) on a new production environment

The best is to get your patches merged by upstream. Of course, this
might ask rework of your local changes. Once merged, you will have less
maintenance work and others might benefit from your changes.

If it's really not possible (which I tend to not believe), the way to
maintain and deploy your own gems depends on the number of systems where
you have to deploy it.

A few choices:

* Vendorize it
* Package your own gem from the altered code
* Monkey-patch the gem in your lib folder

There's probably more options.

monkey patch +1

vendorize isn’t good choice for maintenance.

Use AOP with include module chain methology(http://stackoverflow.com/questions/3689736/rails-3-alias-method-chain-still-used) not alias_method_chain.

2012년 3월 21일 수요일 오전 11시 45분 59초 UTC+9, (알 수 없음) 님의 말:

If you're using bundler (which you should be), then you can:
1) Fork the gem and checkout that fork
2) Make your modifications to your fork (include tests if possible)
and push back to origin.
3) Update bundler to pull from your forked repository instead of
rubygems for that particular gem:

    gem 'event_calendar', :git => 'git://github.com/your_account_name/
event_calendar.git'

This way you have an authoritative version of your changes to the gem
on github that your project can answer, and you can use the power of
git to merge in upstream changes, etc. as you go along. And if it
makes sense you can make a Pull Request so you no longer need to
maintain the code.

A side note, since your fork is public if you want to do more local
integration testing in #2 before pushing it back to origin you can
point bundler at a local git repository too:

    gem 'event_calendar', :git => '/some/path/to/local/checkouts/
event_calendar'

And that way you can make changes, rebase, etc. locally to get
everything happy, and then when ready push to origin and update your
Gemfile.

\Peter

Michael Pavling wrote in post #1052592:

For a project I used the gem 'event_calendar'. However, there were a
couple things I had to manually change within the gem source to suit my
needs.

How would I go about to deploy this in production 'the rails way'?

A few choices:

* Vendorize it
* Package your own gem from the altered code
* Monkey-patch the gem in your lib folder

There's probably more options.

Thanks for all the replies. I decided to go with vendorizing the gem,
since the changes were so application specific I did not want to deploy
the modified gem apart from the application.

Running into the following problem now though. Whenever I load the model
that uses some of the gem functionality, I get this error:

NoMethodError: undefined method `has_event_calendar' for
#<Class:0x45e2308>

The line in the gemfile reads:
gem 'event-calendar', :require => 'event_calendar', :path =>
'vendor/gems/event-calendar-2.3.3'

When I go into the console, I do seem to have access to the gem's
namespace (for example, EventCalendar module is known)

What am I doing wrong?

Ignore that last post... I discovered something went wrong with the
vendorization of the gem and files did not end up in the correct
location.

Its working now.