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

Eager load the constants #102

Merged
merged 1 commit into from
Aug 16, 2017
Merged
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
16 changes: 13 additions & 3 deletions lib/global_id.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
require 'global_id/global_id'
require 'active_support'

autoload :SignedGlobalID, 'global_id/signed_global_id'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we also need to eager load this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree.
But SignedGlobalID is defined at Top level. Is eager load usable in that case?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really. We can implement self.eager_load! in GlobalID and make it require that file.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood, thank you! I fixed.


class GlobalID
autoload :Locator, 'global_id/locator'
autoload :Identification, 'global_id/identification'
autoload :Verifier, 'global_id/verifier'
extend ActiveSupport::Autoload

eager_autoload do
autoload :Locator
autoload :Identification
autoload :Verifier
end

def self.eager_load!
super
require 'global_id/signed_global_id'
end
end
1 change: 1 addition & 0 deletions lib/global_id/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class GlobalID
# Set up the signed GlobalID verifier and include Active Record support.
class Railtie < Rails::Railtie # :nodoc:
config.global_id = ActiveSupport::OrderedOptions.new
config.eager_load_namespaces << GlobalID

initializer 'global_id' do |app|

Expand Down