Rails - 扩展Ruby Gem

Ada*_*ite 1 ruby rubygems ruby-on-rails activemerchant

我想为ActiveMerchant gem添加一些功能以便测试PayPal Express网关,已经尝试了拉取请求,但是在Github上被拒绝了.

我想在ActiveMerchant Billing模块中添加一个类:

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

      # some codes here

    end
  end
end
Run Code Online (Sandbox Code Playgroud)

我通过下载并将gem拉入我的项目本地并在那里展示我的新文件成功完成了这项工作:

#Gemfile
gem 'activemerchant', '1.34.1', path: "vendor/gems/activemerchant-1.34.1", require: 'active_merchant'
Run Code Online (Sandbox Code Playgroud)

但当然,这不是最好的主意,因为如果我需要,我必须手动提取任何更新.

有没有什么办法可以使用从RubyGems源中提取的gem将类添加到模块中?

谢谢

编辑

将它放在lib文件夹中应该可以工作,但是我的代码需要从gem继承的一些类,例如:

require File.dirname(__FILE__) + '/paypal/paypal_common_api'
require File.dirname(__FILE__) + '/paypal/paypal_express_response'
require File.dirname(__FILE__) + '/paypal_express_common'
Run Code Online (Sandbox Code Playgroud)

将gem.dirname(FILE)替换为安装gem的位置......这在服务器环境中会有所不同吗?

hou*_*se9 7

将activemerchant添加到Gemfile,捆绑安装

config/application.rb化妆确保LIB包含在自动加载路径

# need to uncomment or add this to the configuration
config.autoload_paths += %W(#{config.root}/lib)
Run Code Online (Sandbox Code Playgroud)

使用嵌套目录将类放在文件中以匹配模块

# lib/active_merchant/billing/paypal_bogus_gateway.rb
Run Code Online (Sandbox Code Playgroud)

不要在你的虚假网关,rails中包含任何require语句(通过bundler应该要求Gemfile中的所有内容)

重启rails