Skip to content

Commit

Permalink
Add "frozen_string_literal: true" magic header (#430)
Browse files Browse the repository at this point in the history
* Add "frozen_string_literal: true" magic header

* 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!'
  • Loading branch information
n-rodriguez authored Nov 4, 2024
1 parent ccfb3f3 commit b092f04
Show file tree
Hide file tree
Showing 25 changed files with 57 additions and 6 deletions.
2 changes: 2 additions & 0 deletions lib/sitemap_generator.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'sitemap_generator/simple_namer'
require 'sitemap_generator/builder'
require 'sitemap_generator/link_set'
Expand Down
2 changes: 2 additions & 0 deletions lib/sitemap_generator/adapters/aws_sdk_adapter.rb
Original file line number Diff line number Diff line change
@@ -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."
Expand Down
2 changes: 2 additions & 0 deletions lib/sitemap_generator/adapters/file_adapter.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module SitemapGenerator
# Class for writing out data to a file.
class FileAdapter
Expand Down
2 changes: 2 additions & 0 deletions lib/sitemap_generator/adapters/fog_adapter.rb
Original file line number Diff line number Diff line change
@@ -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."
Expand Down
2 changes: 2 additions & 0 deletions lib/sitemap_generator/adapters/google_storage_adapter.rb
Original file line number Diff line number Diff line change
@@ -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."
Expand Down
2 changes: 2 additions & 0 deletions lib/sitemap_generator/adapters/s3_adapter.rb
Original file line number Diff line number Diff line change
@@ -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."
Expand Down
2 changes: 2 additions & 0 deletions lib/sitemap_generator/adapters/wave_adapter.rb
Original file line number Diff line number Diff line change
@@ -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."
Expand Down
2 changes: 2 additions & 0 deletions lib/sitemap_generator/application.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'pathname'

module SitemapGenerator
Expand Down
4 changes: 3 additions & 1 deletion lib/sitemap_generator/builder.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# frozen_string_literal: true

require 'sitemap_generator/builder/sitemap_file'
require 'sitemap_generator/builder/sitemap_index_file'
require 'sitemap_generator/builder/sitemap_url'
require 'sitemap_generator/builder/sitemap_index_url'

module SitemapGenerator::Builder
LinkHolder = Struct.new(:link, :options)
end
end
6 changes: 4 additions & 2 deletions lib/sitemap_generator/builder/sitemap_file.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'zlib'
require 'fileutils'
require 'sitemap_generator/helpers/number_helper'
Expand All @@ -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
<?xml version="1.0" encoding="UTF-8"?>
<urlset
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
Expand Down
6 changes: 4 additions & 2 deletions lib/sitemap_generator/builder/sitemap_index_file.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module SitemapGenerator
module Builder
class SitemapIndexFile < SitemapFile
Expand All @@ -10,8 +12,8 @@ def initialize(opts={})
@location = opts.is_a?(Hash) ? SitemapGenerator::SitemapIndexLocation.new(opts) : opts
@link_count = 0
@sitemaps_link_count = 0
@xml_content = '' # XML urlset content
@xml_wrapper_start = <<-HTML
@xml_content = +'' # XML urlset content
@xml_wrapper_start = +<<-HTML
<?xml version="1.0" encoding="UTF-8"?>
<sitemapindex
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
Expand Down
2 changes: 2 additions & 0 deletions lib/sitemap_generator/builder/sitemap_index_url.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'builder'

module SitemapGenerator
Expand Down
2 changes: 2 additions & 0 deletions lib/sitemap_generator/builder/sitemap_url.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'builder'
require 'uri'
require 'time'
Expand Down
2 changes: 2 additions & 0 deletions lib/sitemap_generator/core_ext.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

Dir["#{File.dirname(__FILE__)}/core_ext/**/*.rb"].sort.each do |path|
require path
end
2 changes: 2 additions & 0 deletions lib/sitemap_generator/core_ext/big_decimal.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'bigdecimal'

begin
Expand Down
2 changes: 2 additions & 0 deletions lib/sitemap_generator/core_ext/numeric.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class SitemapGenerator::Numeric
KILOBYTE = 1024
MEGABYTE = KILOBYTE * 1024
Expand Down
2 changes: 2 additions & 0 deletions lib/sitemap_generator/helpers/number_helper.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# require "sitemap_generator/core_ext/big_decimal/conversions"
require "sitemap_generator/utilities"

Expand Down
2 changes: 2 additions & 0 deletions lib/sitemap_generator/interpreter.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'sitemap_generator'

module SitemapGenerator
Expand Down
2 changes: 2 additions & 0 deletions lib/sitemap_generator/link_set.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'builder'

# A LinkSet provisions a bunch of links to sitemap files. It also writes the index file
Expand Down
2 changes: 2 additions & 0 deletions lib/sitemap_generator/railtie.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module SitemapGenerator
class Railtie < Rails::Railtie
rake_tasks do
Expand Down
2 changes: 2 additions & 0 deletions lib/sitemap_generator/simple_namer.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module SitemapGenerator
# A class for generating sitemap filenames.
#
Expand Down
4 changes: 3 additions & 1 deletion lib/sitemap_generator/sitemap_location.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'sitemap_generator/helpers/number_helper'

module SitemapGenerator
Expand Down Expand Up @@ -108,7 +110,7 @@ def filesize
def filename
raise SitemapGenerator::SitemapError, "No filename or namer set" unless self[:filename] || self[:namer]
unless self[:filename]
self.send(:[]=, :filename, self[:namer].to_s, :super => 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.
Expand Down
2 changes: 2 additions & 0 deletions lib/sitemap_generator/tasks.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# require this file to load the tasks
require 'rake'

Expand Down
2 changes: 2 additions & 0 deletions lib/sitemap_generator/templates.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module SitemapGenerator
# Provide convenient access to template files. E.g.
#
Expand Down
3 changes: 3 additions & 0 deletions lib/sitemap_generator/utilities.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module SitemapGenerator
module Utilities
extend self
Expand Down Expand Up @@ -140,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
Expand Down

0 comments on commit b092f04

Please sign in to comment.