Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically eager load all integrations when in Rails context #366

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/offsite_payments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ def self.integration(name)
Integrations.const_get("#{name.to_s.downcase}".camelize)
end

def self.eager_load!
Integrations.eager_load!
nil
end

mattr_accessor :mode
self.mode = :production

Expand All @@ -42,3 +47,5 @@ def self.test?

CURRENCIES_WITHOUT_FRACTIONS = [ 'BIF', 'BYR', 'CLP', 'CVE', 'DJF', 'GNF', 'ISK', 'JPY', 'KMF', 'KRW', 'PYG', 'RWF', 'TWD', 'UGX', 'VND', 'VUV', 'XAF', 'XOF', 'XPF' ]
end

require "offsite_payments/railtie" if defined? Rails::Railtie
7 changes: 7 additions & 0 deletions lib/offsite_payments/integrations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,12 @@ module Integrations
# Register for autoloading
autoload integration_class, f
end

def self.eager_load!
constants.each do |const_name|
const_get(const_name)
end
nil
end
end
end
7 changes: 7 additions & 0 deletions lib/offsite_payments/railtie.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module OffsitePayments
class Railtie < Rails::Railtie
config.before_eager_load do
config.eager_load_namespace << OffsitePayments
end
end
end
1 change: 1 addition & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
require 'json'
require 'nokogiri'

require 'active_support'
require 'active_support/core_ext/integer/time'
require 'active_support/core_ext/numeric/time'
require 'active_support/core_ext/time/acts_like'
Expand Down