From 9680c3f0d16f42de2552381932e74aa4881ee964 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Tue, 9 Jan 2024 23:56:44 +0100 Subject: [PATCH 1/2] Add "frozen_string_literal: true" magic header --- lib/sitemap_generator.rb | 2 ++ lib/sitemap_generator/adapters/aws_sdk_adapter.rb | 2 ++ lib/sitemap_generator/adapters/file_adapter.rb | 2 ++ lib/sitemap_generator/adapters/fog_adapter.rb | 2 ++ lib/sitemap_generator/adapters/google_storage_adapter.rb | 2 ++ lib/sitemap_generator/adapters/s3_adapter.rb | 2 ++ lib/sitemap_generator/adapters/wave_adapter.rb | 2 ++ lib/sitemap_generator/application.rb | 2 ++ lib/sitemap_generator/builder.rb | 4 +++- lib/sitemap_generator/builder/sitemap_file.rb | 6 ++++-- lib/sitemap_generator/builder/sitemap_index_file.rb | 6 ++++-- lib/sitemap_generator/builder/sitemap_index_url.rb | 2 ++ lib/sitemap_generator/builder/sitemap_url.rb | 2 ++ lib/sitemap_generator/core_ext.rb | 2 ++ lib/sitemap_generator/core_ext/big_decimal.rb | 2 ++ lib/sitemap_generator/core_ext/numeric.rb | 2 ++ lib/sitemap_generator/helpers/number_helper.rb | 2 ++ lib/sitemap_generator/interpreter.rb | 2 ++ lib/sitemap_generator/link_set.rb | 2 ++ lib/sitemap_generator/railtie.rb | 2 ++ lib/sitemap_generator/simple_namer.rb | 2 ++ lib/sitemap_generator/sitemap_location.rb | 4 +++- lib/sitemap_generator/tasks.rb | 2 ++ lib/sitemap_generator/templates.rb | 2 ++ lib/sitemap_generator/utilities.rb | 2 ++ 25 files changed, 56 insertions(+), 6 deletions(-) diff --git a/lib/sitemap_generator.rb b/lib/sitemap_generator.rb index 5b52f6d9..07d2511e 100644 --- a/lib/sitemap_generator.rb +++ b/lib/sitemap_generator.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'sitemap_generator/simple_namer' require 'sitemap_generator/builder' require 'sitemap_generator/link_set' diff --git a/lib/sitemap_generator/adapters/aws_sdk_adapter.rb b/lib/sitemap_generator/adapters/aws_sdk_adapter.rb index 343b2559..f26d2057 100644 --- a/lib/sitemap_generator/adapters/aws_sdk_adapter.rb +++ b/lib/sitemap_generator/adapters/aws_sdk_adapter.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + if !defined?(Aws::S3::Resource) or !defined?(Aws::Credentials) raise LoadError, "Error: `Aws::S3::Resource` and/or `Aws::Credentials` are not defined.\n\n"\ "Please `require 'aws-sdk'` - or another library that defines these classes." diff --git a/lib/sitemap_generator/adapters/file_adapter.rb b/lib/sitemap_generator/adapters/file_adapter.rb index a096e241..992a67fe 100644 --- a/lib/sitemap_generator/adapters/file_adapter.rb +++ b/lib/sitemap_generator/adapters/file_adapter.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module SitemapGenerator # Class for writing out data to a file. class FileAdapter diff --git a/lib/sitemap_generator/adapters/fog_adapter.rb b/lib/sitemap_generator/adapters/fog_adapter.rb index 2982534a..7747d59f 100644 --- a/lib/sitemap_generator/adapters/fog_adapter.rb +++ b/lib/sitemap_generator/adapters/fog_adapter.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + if !defined?(Fog::Storage) raise LoadError, "Error: `Fog::Storage` is not defined.\n\n"\ "Please `require 'fog'` - or another library that defines this class." diff --git a/lib/sitemap_generator/adapters/google_storage_adapter.rb b/lib/sitemap_generator/adapters/google_storage_adapter.rb index fe0fee91..02612ce1 100644 --- a/lib/sitemap_generator/adapters/google_storage_adapter.rb +++ b/lib/sitemap_generator/adapters/google_storage_adapter.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + if !defined?(Google::Cloud::Storage) raise LoadError, "Error: `Google::Cloud::Storage` is not defined.\n\n"\ "Please `require 'google/cloud/storage'` - or another library that defines this class." diff --git a/lib/sitemap_generator/adapters/s3_adapter.rb b/lib/sitemap_generator/adapters/s3_adapter.rb index d4a6a126..81e013de 100644 --- a/lib/sitemap_generator/adapters/s3_adapter.rb +++ b/lib/sitemap_generator/adapters/s3_adapter.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + if !defined?(Fog::Storage) raise LoadError, "Error: `Fog::Storage` is not defined.\n\n"\ "Please `require 'fog-aws'` - or another library that defines this class." diff --git a/lib/sitemap_generator/adapters/wave_adapter.rb b/lib/sitemap_generator/adapters/wave_adapter.rb index 8b049bd7..6cd1ebb2 100644 --- a/lib/sitemap_generator/adapters/wave_adapter.rb +++ b/lib/sitemap_generator/adapters/wave_adapter.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + if !defined?(::CarrierWave::Uploader::Base) raise LoadError, "Error: `CarrierWave::Uploader::Base` is not defined.\n\n"\ "Please `require 'carrierwave'` - or another library that defines this class." diff --git a/lib/sitemap_generator/application.rb b/lib/sitemap_generator/application.rb index 4dd5fd4f..39affdc8 100644 --- a/lib/sitemap_generator/application.rb +++ b/lib/sitemap_generator/application.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'pathname' module SitemapGenerator diff --git a/lib/sitemap_generator/builder.rb b/lib/sitemap_generator/builder.rb index a1d4fa27..1fec477a 100644 --- a/lib/sitemap_generator/builder.rb +++ b/lib/sitemap_generator/builder.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'sitemap_generator/builder/sitemap_file' require 'sitemap_generator/builder/sitemap_index_file' require 'sitemap_generator/builder/sitemap_url' @@ -5,4 +7,4 @@ module SitemapGenerator::Builder LinkHolder = Struct.new(:link, :options) -end \ No newline at end of file +end diff --git a/lib/sitemap_generator/builder/sitemap_file.rb b/lib/sitemap_generator/builder/sitemap_file.rb index 9979100d..a7000805 100644 --- a/lib/sitemap_generator/builder/sitemap_file.rb +++ b/lib/sitemap_generator/builder/sitemap_file.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'zlib' require 'fileutils' require 'sitemap_generator/helpers/number_helper' @@ -24,8 +26,8 @@ def initialize(opts={}) @location = opts.is_a?(Hash) ? SitemapGenerator::SitemapLocation.new(opts) : opts @link_count = 0 @news_count = 0 - @xml_content = '' # XML urlset content - @xml_wrapper_start = <<-HTML + @xml_content = +'' # XML urlset content + @xml_wrapper_start = +<<-HTML true) + self.send(:[]=, :filename, +self[:namer].to_s, :super => true) # Post-process the filename for our compression settings. # Strip the `.gz` from the extension if we aren't compressing this file. diff --git a/lib/sitemap_generator/tasks.rb b/lib/sitemap_generator/tasks.rb index d33c0137..9a5fbe28 100644 --- a/lib/sitemap_generator/tasks.rb +++ b/lib/sitemap_generator/tasks.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # require this file to load the tasks require 'rake' diff --git a/lib/sitemap_generator/templates.rb b/lib/sitemap_generator/templates.rb index 5b6f3522..78ec510e 100644 --- a/lib/sitemap_generator/templates.rb +++ b/lib/sitemap_generator/templates.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module SitemapGenerator # Provide convenient access to template files. E.g. # diff --git a/lib/sitemap_generator/utilities.rb b/lib/sitemap_generator/utilities.rb index 6c080395..aa6e883b 100644 --- a/lib/sitemap_generator/utilities.rb +++ b/lib/sitemap_generator/utilities.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module SitemapGenerator module Utilities extend self From 7ef3c4188048925fd70c266b18b9eba8d94e23fd Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Fri, 12 Jan 2024 00:57:17 +0100 Subject: [PATCH 2/2] Fix FrozenError: can't modify frozen String: "google" (FrozenError) when running ping_search_engines Backtrace: FrozenError: can't modify frozen String: "google" (FrozenError) /Users/nicolas/PROJECTS/CONCERTO/concerto/.bundle/ruby/3.2.0/bundler/gems/sitemap_generator-426a0b86cb56/lib/sitemap_generator/utilities.rb:145:in `gsub!' /Users/nicolas/PROJECTS/CONCERTO/concerto/.bundle/ruby/3.2.0/bundler/gems/sitemap_generator-426a0b86cb56/lib/sitemap_generator/utilities.rb:145:in `titleize' /Users/nicolas/PROJECTS/CONCERTO/concerto/.bundle/ruby/3.2.0/bundler/gems/sitemap_generator-426a0b86cb56/lib/sitemap_generator/link_set.rb:296:in `block in ping_search_engines' /Users/nicolas/PROJECTS/CONCERTO/concerto/.bundle/ruby/3.2.0/bundler/gems/sitemap_generator-426a0b86cb56/lib/sitemap_generator/link_set.rb:294:in `each' /Users/nicolas/PROJECTS/CONCERTO/concerto/.bundle/ruby/3.2.0/bundler/gems/sitemap_generator-426a0b86cb56/lib/sitemap_generator/link_set.rb:294:in `ping_search_engines' /Users/nicolas/PROJECTS/CONCERTO/concerto/.bundle/ruby/3.2.0/bundler/gems/sitemap_generator-426a0b86cb56/lib/sitemap_generator.rb:44:in `method_missing' /Users/nicolas/PROJECTS/CONCERTO/concerto/app/concepts/system/operation/refresh_sitemap.rb:11:in `refresh_sitemap!' --- lib/sitemap_generator/utilities.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/sitemap_generator/utilities.rb b/lib/sitemap_generator/utilities.rb index aa6e883b..b5980a91 100644 --- a/lib/sitemap_generator/utilities.rb +++ b/lib/sitemap_generator/utilities.rb @@ -142,6 +142,7 @@ def with_warnings(flag) end def titleize(string) + string = string.dup if string.frozen? string.gsub!(/_/, ' ') string.split(/(\W)/).map(&:capitalize).join end