From cd21246e7db8db399a26cf6aa9b6ad0e00dac513 Mon Sep 17 00:00:00 2001 From: Jeremy Evans Date: Fri, 1 Nov 2024 14:03:04 -0700 Subject: [PATCH] Make Roda.freeze work if already frozen when using the autoload_{hash_branches,named_routes} plugins --- CHANGELOG | 2 ++ lib/roda/plugins/autoload_hash_branches.rb | 2 +- lib/roda/plugins/autoload_named_routes.rb | 2 +- spec/plugin/autoload_hash_branches_spec.rb | 2 +- spec/plugin/autoload_named_routes_spec.rb | 2 +- 5 files changed, 6 insertions(+), 4 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index e91ba8bf..be8e00eb 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,7 @@ = master +* Make Roda.freeze work if already frozen when using the autoload_{hash_branches,named_routes} plugins (jeremyevans) + * Allow response.content_security_plugin = false to avoid setting policy in content_security_policy plugin (jeremyevans) = 3.85.0 (2024-10-11) diff --git a/lib/roda/plugins/autoload_hash_branches.rb b/lib/roda/plugins/autoload_hash_branches.rb index 890b242a..9e3978e0 100644 --- a/lib/roda/plugins/autoload_hash_branches.rb +++ b/lib/roda/plugins/autoload_hash_branches.rb @@ -68,7 +68,7 @@ def autoload_hash_branch_dir(namespace='', dir) # Eagerly load all hash branches when freezing the application. def freeze - opts.delete(:autoload_hash_branch_files).each{|file| require file} + opts.delete(:autoload_hash_branch_files).each{|file| require file} unless opts.frozen? super end end diff --git a/lib/roda/plugins/autoload_named_routes.rb b/lib/roda/plugins/autoload_named_routes.rb index 2a44a938..9e09ece9 100644 --- a/lib/roda/plugins/autoload_named_routes.rb +++ b/lib/roda/plugins/autoload_named_routes.rb @@ -54,7 +54,7 @@ def autoload_named_route(namespace=nil, name, file) # Eagerly load all autoloaded named routes when freezing the application. def freeze - opts.delete(:autoload_named_route_files).each{|file| require file} + opts.delete(:autoload_named_route_files).each{|file| require file} unless opts.frozen? super end end diff --git a/spec/plugin/autoload_hash_branches_spec.rb b/spec/plugin/autoload_hash_branches_spec.rb index 93439256..99b8f7fb 100644 --- a/spec/plugin/autoload_hash_branches_spec.rb +++ b/spec/plugin/autoload_hash_branches_spec.rb @@ -89,7 +89,7 @@ def check_autoload_hash_branches $roda_app = @app @app.opts[:loaded] = [] - @app.freeze + 2.times{@app.freeze} @app.opts[:loaded].must_equal [:a, :b, :a_c, :a_d, :a_e] body('/c').must_equal '-' body('/b').must_equal 'b' diff --git a/spec/plugin/autoload_named_routes_spec.rb b/spec/plugin/autoload_named_routes_spec.rb index 4d467481..ca1c0855 100644 --- a/spec/plugin/autoload_named_routes_spec.rb +++ b/spec/plugin/autoload_named_routes_spec.rb @@ -76,7 +76,7 @@ $roda_app = @app @app.opts[:loaded] = [] - @app.freeze + 2.times{@app.freeze} @app.opts[:loaded].must_equal [:a, :b, :a_c, :a_d, :a_e] body('/c').must_equal '-' body('/b').must_equal 'b'