Search code examples
ruby-on-railsrubyrubygemsactivemerchant

Rails - Extend a Ruby Gem


I want to add some functionality to the ActiveMerchant gem in order to test the PayPal Express gateway, a pull request has been attempted for this but was turned down on Github.

I want to add a single class to the ActiveMerchant Billing module:

module ActiveMerchant #:nodoc:
  module Billing #:nodoc:
    class PaypalBogusGateway < BogusGateway

      # some codes here

    end
  end
end

I have done this successfully by downloading and pulling the gem into my project locally and trhowing my new file in there:

#Gemfile
gem 'activemerchant', '1.34.1', path: "vendor/gems/activemerchant-1.34.1", require: 'active_merchant'

But of course, that's not the best idea because I'll have to manually pull any updates if I want them.

Is there any way I can add the class to their module using their gem that's been pulled from the RubyGems source?

Thanks

EDIT

Putting it in the lib folder should work but my code requires some classes from the gem to inherit from, like:

require File.dirname(__FILE__) + '/paypal/paypal_common_api'
require File.dirname(__FILE__) + '/paypal/paypal_express_response'
require File.dirname(__FILE__) + '/paypal_express_common'

replacing File.dirname(FILE) with wherever the gem is installed... This will be different across server environments right?


Solution

  • You might want to just fork the project on GitHub and add your changes to it. Even if it is just a single class. And then, in your Gemfile, do this:

    gem "active_merchant", :git => "git://github.com/<your-user-name-here>/active_merchant.git"