Skip to content

Commit

Permalink
[Chore] Frozen string literal, finally
Browse files Browse the repository at this point in the history
Ruby 3.4 makes string literals frozen by default,
so this change will be required for the future.
  • Loading branch information
okuramasafumi committed Jul 15, 2024
1 parent dcd5445 commit 5b0196d
Show file tree
Hide file tree
Showing 51 changed files with 101 additions and 6 deletions.
4 changes: 0 additions & 4 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,6 @@ Style/DocumentationMethod:
Exclude:
- 'README.md'

# This might be true in the future, but not many good things
Style/FrozenStringLiteralComment:
Enabled: false

# I don't want to think about error class in example code
Style/ImplicitRuntimeError:
Exclude:
Expand Down
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

source 'https://rubygems.org'

# Specify your gem's dependencies in alba.gemspec
Expand Down
2 changes: 2 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'bundler/gem_tasks'
require 'rake/testtask'

Expand Down
1 change: 1 addition & 0 deletions bin/console
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require 'bundler/setup'
require 'alba'
Expand Down
2 changes: 2 additions & 0 deletions gemfiles/without_active_support.gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

source 'https://rubygems.org'

gem 'minitest', '~> 5.14' # For test
Expand Down
2 changes: 2 additions & 0 deletions gemfiles/without_oj.gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

source 'https://rubygems.org'

gem 'activesupport', require: false # For backend
Expand Down
2 changes: 2 additions & 0 deletions lib/alba.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'json'
require_relative 'alba/version'
require_relative 'alba/errors'
Expand Down
2 changes: 2 additions & 0 deletions lib/alba/association.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Alba
# Representing association
# @api private
Expand Down
2 changes: 2 additions & 0 deletions lib/alba/conditional_attribute.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_relative 'association'
require_relative 'constants'
require 'ostruct'
Expand Down
2 changes: 2 additions & 0 deletions lib/alba/constants.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# This file includes public constants to prevent circular dependencies.
module Alba
REMOVE_KEY = Object.new.freeze # A constant to remove key from serialized JSON
Expand Down
2 changes: 2 additions & 0 deletions lib/alba/default_inflector.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

begin
require 'active_support/inflector'
require 'active_support/core_ext/module/delegation'
Expand Down
2 changes: 2 additions & 0 deletions lib/alba/deprecation.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Alba
# Module for printing deprecation warning
# @api private
Expand Down
2 changes: 2 additions & 0 deletions lib/alba/errors.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Alba
# Base class for Errors
class Error < StandardError; end
Expand Down
2 changes: 2 additions & 0 deletions lib/alba/layout.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'erb'
require 'forwardable'

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

module Alba
# Representing nested attribute
# @api private
Expand Down
2 changes: 2 additions & 0 deletions lib/alba/railtie.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Alba
# Rails integration
class Railtie < Rails::Railtie
Expand Down
2 changes: 2 additions & 0 deletions lib/alba/resource.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_relative 'association'
require_relative 'conditional_attribute'
require_relative 'constants'
Expand Down
2 changes: 2 additions & 0 deletions lib/alba/type.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Alba
# Representing type itself, combined with {Alba::TypedAttribute}
class Type
Expand Down
2 changes: 2 additions & 0 deletions lib/alba/typed_attribute.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Alba
# Representing typed attributes to encapsulate logic about types
# @api private
Expand Down
4 changes: 3 additions & 1 deletion lib/alba/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Alba
VERSION = '3.2.0'.freeze
VERSION = '3.2.0'
end
2 changes: 2 additions & 0 deletions test/alba_test.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'test_helper'

class AlbaTest < Minitest::Test
Expand Down
2 changes: 2 additions & 0 deletions test/dependencies/railties_test.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# Rails integration
require 'rails'
require_relative '../test_helper'
Expand Down
2 changes: 2 additions & 0 deletions test/dependencies/test_dependencies.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_relative '../test_helper'

class DependenciesTest < Minitest::Test
Expand Down
2 changes: 2 additions & 0 deletions test/resource_test.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_relative 'test_helper'

class ResourceTest < Minitest::Test
Expand Down
2 changes: 2 additions & 0 deletions test/support/custom_inflector.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# Fake implementation of custom inflector
module CustomInflector
module_function
Expand Down
2 changes: 2 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'simplecov'

require 'simplecov-cobertura'
Expand Down
2 changes: 2 additions & 0 deletions test/usecases/circular_association_test.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# Based on https://github.com/jsonapi-serializer/comparisons
require_relative '../test_helper'
require 'securerandom'
Expand Down
2 changes: 2 additions & 0 deletions test/usecases/collection_test.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_relative '../test_helper'

class CollectionTest < Minitest::Test
Expand Down
2 changes: 2 additions & 0 deletions test/usecases/conditional_attributes_test.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_relative '../test_helper'

class ConditionalAttributesTest < Minitest::Test
Expand Down
2 changes: 2 additions & 0 deletions test/usecases/custom_type_test.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_relative '../test_helper'

class CustomTypeTest < Minitest::Test
Expand Down
2 changes: 2 additions & 0 deletions test/usecases/field_selection_test.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_relative '../test_helper'

class FieldSelectionTest < Minitest::Test
Expand Down
2 changes: 2 additions & 0 deletions test/usecases/helper_test.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_relative '../test_helper'

class HelperTest < Minitest::Test
Expand Down
2 changes: 2 additions & 0 deletions test/usecases/inheritance_and_ignorance_test.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_relative '../test_helper'

class InheritanceAndIgnoranceTest < Minitest::Test
Expand Down
2 changes: 2 additions & 0 deletions test/usecases/key_transform_test.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_relative '../test_helper'
require_relative '../support/custom_inflector'

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

require_relative '../test_helper'

class LayoutTest < Minitest::Test
Expand Down
2 changes: 2 additions & 0 deletions test/usecases/many_test.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_relative '../test_helper'

class ManyTest < Minitest::Test
Expand Down
2 changes: 2 additions & 0 deletions test/usecases/meta_test.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_relative '../test_helper'

class MetaTest < Minitest::Test
Expand Down
2 changes: 2 additions & 0 deletions test/usecases/nested_array_and_hash_test.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_relative '../test_helper'

class HashAttributeTest < Minitest::Test
Expand Down
2 changes: 2 additions & 0 deletions test/usecases/nested_attribute_test.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_relative '../test_helper'

class NestedAttributeTest < Minitest::Test
Expand Down
2 changes: 2 additions & 0 deletions test/usecases/nil_filtering_test.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_relative '../test_helper'

class NilFilteringTest < Minitest::Test
Expand Down
2 changes: 2 additions & 0 deletions test/usecases/nil_handler_test.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_relative '../test_helper'

class NilHandlerTest < Minitest::Test
Expand Down
2 changes: 2 additions & 0 deletions test/usecases/no_association_test.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_relative '../test_helper'

class NoAssociationTest < Minitest::Test
Expand Down
2 changes: 2 additions & 0 deletions test/usecases/object_method_and_resource_method_test.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_relative '../test_helper'

class ObjectMethodAndResourceMethodTest < Minitest::Test
Expand Down
2 changes: 2 additions & 0 deletions test/usecases/on_error_test.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_relative '../test_helper'

class OnErrorTest < Minitest::Test
Expand Down
4 changes: 3 additions & 1 deletion test/usecases/one_test.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_relative '../test_helper'

class OneTest < Minitest::Test
Expand Down Expand Up @@ -100,7 +102,7 @@ class UserResource4

one :profile,
proc { |profile, params|
profile.email.sub!('@', params[:replace_atmark_with]) if params[:replace_atmark_with]
profile.email = profile.email.sub('@', params[:replace_atmark_with]) if params[:replace_atmark_with]
profile
},
resource: ProfileResource
Expand Down
2 changes: 2 additions & 0 deletions test/usecases/params_test.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_relative '../test_helper'

class ParamsTest < Minitest::Test
Expand Down
2 changes: 2 additions & 0 deletions test/usecases/root_key_collection_test.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_relative '../test_helper'

class RootKeyCollectionTest < Minitest::Test
Expand Down
2 changes: 2 additions & 0 deletions test/usecases/type_validation_test.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_relative '../test_helper'

class TypeValidationTest < Minitest::Test
Expand Down
2 changes: 2 additions & 0 deletions test/usecases/user_defined_serializable_hash_test.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_relative '../test_helper'

class UserDefinedSerializableHashTest < Minitest::Test
Expand Down
2 changes: 2 additions & 0 deletions test/usecases/with_inference_test.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_relative '../test_helper'
require_relative '../support/custom_inflector'

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

require_relative '../test_helper'

class WithStructTest < Minitest::Test
Expand Down

0 comments on commit 5b0196d

Please sign in to comment.