Skip to content

Commit

Permalink
added option to skip eager loading
Browse files Browse the repository at this point in the history
  • Loading branch information
daddyz committed Jan 18, 2024
1 parent ba18622 commit 3c39f4e
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
6 changes: 6 additions & 0 deletions lib/phonelib/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@ module Core
# eagerly initialize the gem, loads data into memory. not required, initialization is done lazily otherwise, but
# may be desirable in production enviroments to avoid initialization time on first use.
def eager_load!
return if @@skip_eager_loading
phone_data
phone_ext_data
end

@@skip_eager_loading = false
def skip_eager_loading!
@@skip_eager_loading = true
end

# getter for phone data for other modules of gem, can be used outside
# @return [Hash] all data for phone parsing
def phone_data
Expand Down
7 changes: 4 additions & 3 deletions spec/dummy/config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,13 @@ class Application < Rails::Application
# parameters by using an attr_accessible or attr_protected declaration.
if Rails::VERSION::MAJOR < 5
config.active_record.whitelist_attributes = true
config.assets.enabled = true

# Version of your assets, change this if you want to expire all your assets
config.assets.version = '1.0'
end
# Enable the asset pipeline
config.assets.enabled = true

# Version of your assets, change this if you want to expire all your assets
config.assets.version = '1.0'
end
end

Expand Down
6 changes: 4 additions & 2 deletions spec/dummy/config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
# Only use best-standards-support built into browsers
config.action_dispatch.best_standards_support = :builtin

config.eager_load = true

# Raise exception on mass assignment protection for Active Record models
#config.active_record.mass_assignment_sanitizer = :strict

Expand All @@ -30,8 +32,8 @@
#config.active_record.auto_explain_threshold_in_seconds = 0.5

# Do not compress assets
config.assets.compress = false
#config.assets.compress = false

# Expands the lines which load the assets
config.assets.debug = true
#config.assets.debug = true
end
1 change: 1 addition & 0 deletions spec/dummy/config/initializers/phonelib.rb
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
Phonelib.override_phone_data = "#{Rails.root}/lib/override_phone_data.dat"
Phonelib.skip_eager_loading!

0 comments on commit 3c39f4e

Please sign in to comment.