1- require 'rails_admin/config/lazy_model '
1+ require 'rails_admin/config/model '
22require 'rails_admin/config/sections/list'
33require 'active_support/core_ext/module/attribute_accessors'
44
@@ -20,6 +20,10 @@ module Config
2020
2121 DEFAULT_CURRENT_USER = proc { }
2222
23+ # Variables to track initialization process
24+ @initialized = false
25+ @deferred_blocks = [ ]
26+
2327 class << self
2428 # Application title, can be an array of two elements
2529 attr_accessor :main_app_name
@@ -82,6 +86,22 @@ class << self
8286 attr_accessor :navigation_static_links
8387 attr_accessor :navigation_static_label
8488
89+ # Finish initialization by executing deferred configuration blocks
90+ def initialize!
91+ @deferred_blocks . each { |block | block . call ( self ) }
92+ @deferred_blocks . clear
93+ @initialized = true
94+ end
95+
96+ # Evaluate the given block either immediately or lazily, based on initialization status.
97+ def apply ( &block )
98+ if @initialized
99+ block . call ( self )
100+ else
101+ @deferred_blocks << block
102+ end
103+ end
104+
85105 # Setup authentication to be run as a before filter
86106 # This is run inside the controller instance so you can setup any authentication you need to
87107 #
@@ -235,8 +255,8 @@ def model(entity, &block)
235255 end
236256 end
237257
238- @registry [ key ] ||= RailsAdmin ::Config ::LazyModel . new ( entity )
239- @registry [ key ] . add_deferred_block ( &block ) if block
258+ @registry [ key ] ||= RailsAdmin ::Config ::Model . new ( entity )
259+ @registry [ key ] . instance_eval ( &block ) if block && @registry [ key ] . abstract_model
240260 @registry [ key ]
241261 end
242262
@@ -311,10 +331,17 @@ def reset_all_models
311331 @registry = { }
312332 end
313333
334+ # Perform reset, then load RailsAdmin initializer again
335+ def reload!
336+ @initialized = false
337+ reset
338+ load RailsAdmin ::Engine . config . initializer_path
339+ initialize!
340+ end
341+
314342 # Get all models that are configured as visible sorted by their weight and label.
315343 #
316344 # @see RailsAdmin::Config::Hideable
317-
318345 def visible_models ( bindings )
319346 visible_models_with_bindings ( bindings ) . sort do |a , b |
320347 if ( weight_order = a . weight <=> b . weight ) == 0
0 commit comments