Skip to content

Commit

Permalink
Merge pull request #297 from Shopify/better-control-over-eager-loading
Browse files Browse the repository at this point in the history
Move expensive resource initialization into an explicit `eager_load!` namespace method
  • Loading branch information
rochlefebvre authored Nov 5, 2024
2 parents 8849e69 + d9bd559 commit 61cf5cf
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## [Unreleased]
- Add `zip_prefixes` for Spain. [#295](https://github.com/Shopify/worldwide/pull/295)
- Move expensive resource initialization into an explicit `eager_load!` namespace method
[#297](https://github.com/Shopify/worldwide/pull/297)
---

## [1.12.1] - 2024-10-15
Expand Down
8 changes: 6 additions & 2 deletions lib/worldwide.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,17 @@
require "worldwide/util"
require "worldwide/zip"

require "worldwide/rails/railtie" if defined?(Rails::Railtie)

module Worldwide
@currencies_cache = {}
@locales_cache = {}

class << self
def eager_load!
Regions.instance
end

def address(**kwargs)
Address.new(**kwargs)
end
Expand Down Expand Up @@ -109,6 +115,4 @@ def units
Units
end
end

Regions.instance # eagerload
end
13 changes: 13 additions & 0 deletions lib/worldwide/rails/railtie.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

require "rails/railtie"

module Worldwide
module Rails
class Railtie < ::Rails::Railtie
initializer "worldwide.setup" do |application|
application.config.eager_load_namespaces << Worldwide
end
end
end
end

0 comments on commit 61cf5cf

Please sign in to comment.