Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "frozen_string_literal: true" magic header #430

Merged
merged 2 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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