From acd7e2ef5baeee4f5c7322a16616aa84cd5932e1 Mon Sep 17 00:00:00 2001 From: Yaw Boakye Date: Mon, 19 Jun 2023 16:59:20 +0100 Subject: [PATCH] add frozen_string_literal magic comment for efficient string storage since we don't mutate any of the string literals after they have been declared. in essence, they're already being used as frozen values. --- lib/jsonapi-resources.rb | 2 ++ lib/jsonapi/active_relation_resource.rb | 2 ++ lib/jsonapi/acts_as_resource_controller.rb | 2 ++ lib/jsonapi/basic_resource.rb | 2 ++ lib/jsonapi/cached_response_fragment.rb | 2 ++ lib/jsonapi/callbacks.rb | 2 ++ lib/jsonapi/compiled_json.rb | 2 ++ lib/jsonapi/configuration.rb | 2 ++ lib/jsonapi/error.rb | 2 ++ lib/jsonapi/error_codes.rb | 2 ++ lib/jsonapi/exceptions.rb | 2 ++ lib/jsonapi/formatter.rb | 2 ++ lib/jsonapi/include_directives.rb | 2 ++ lib/jsonapi/link_builder.rb | 2 ++ lib/jsonapi/mime_types.rb | 2 ++ lib/jsonapi/naive_cache.rb | 2 ++ lib/jsonapi/operation.rb | 2 ++ lib/jsonapi/operation_result.rb | 2 ++ lib/jsonapi/paginator.rb | 2 ++ lib/jsonapi/path.rb | 2 ++ lib/jsonapi/path_segment.rb | 2 ++ lib/jsonapi/processor.rb | 2 ++ lib/jsonapi/relationship.rb | 2 ++ lib/jsonapi/request.rb | 2 ++ lib/jsonapi/resource.rb | 2 ++ lib/jsonapi/resource_controller.rb | 2 ++ lib/jsonapi/resource_controller_metal.rb | 2 ++ lib/jsonapi/resource_fragment.rb | 2 ++ lib/jsonapi/resource_identity.rb | 2 ++ lib/jsonapi/resource_serializer.rb | 2 ++ lib/jsonapi/resource_set.rb | 2 ++ lib/jsonapi/resource_tree.rb | 2 ++ lib/jsonapi/response_document.rb | 2 ++ lib/jsonapi/routing_ext.rb | 2 ++ 34 files changed, 68 insertions(+) diff --git a/lib/jsonapi-resources.rb b/lib/jsonapi-resources.rb index 04fae654f..401d9bbc7 100644 --- a/lib/jsonapi-resources.rb +++ b/lib/jsonapi-resources.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'jsonapi/resources/railtie' require 'jsonapi/naive_cache' require 'jsonapi/compiled_json' diff --git a/lib/jsonapi/active_relation_resource.rb b/lib/jsonapi/active_relation_resource.rb index c86311725..581ed1e02 100644 --- a/lib/jsonapi/active_relation_resource.rb +++ b/lib/jsonapi/active_relation_resource.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module JSONAPI class ActiveRelationResource < BasicResource root_resource diff --git a/lib/jsonapi/acts_as_resource_controller.rb b/lib/jsonapi/acts_as_resource_controller.rb index 5d8b1cd6a..e448fa0ea 100644 --- a/lib/jsonapi/acts_as_resource_controller.rb +++ b/lib/jsonapi/acts_as_resource_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'csv' module JSONAPI diff --git a/lib/jsonapi/basic_resource.rb b/lib/jsonapi/basic_resource.rb index 65e8f57d2..2eeba5c5d 100644 --- a/lib/jsonapi/basic_resource.rb +++ b/lib/jsonapi/basic_resource.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'jsonapi/callbacks' require 'jsonapi/configuration' diff --git a/lib/jsonapi/cached_response_fragment.rb b/lib/jsonapi/cached_response_fragment.rb index 4f2abccdb..5e7d3336a 100644 --- a/lib/jsonapi/cached_response_fragment.rb +++ b/lib/jsonapi/cached_response_fragment.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module JSONAPI class CachedResponseFragment diff --git a/lib/jsonapi/callbacks.rb b/lib/jsonapi/callbacks.rb index 474f50f48..78de6fca9 100644 --- a/lib/jsonapi/callbacks.rb +++ b/lib/jsonapi/callbacks.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'active_support/callbacks' module JSONAPI diff --git a/lib/jsonapi/compiled_json.rb b/lib/jsonapi/compiled_json.rb index 59ce6266b..cd0cc83bb 100644 --- a/lib/jsonapi/compiled_json.rb +++ b/lib/jsonapi/compiled_json.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module JSONAPI class CompiledJson def self.compile(h) diff --git a/lib/jsonapi/configuration.rb b/lib/jsonapi/configuration.rb index 3ab273d24..6cd5d8e1b 100644 --- a/lib/jsonapi/configuration.rb +++ b/lib/jsonapi/configuration.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'jsonapi/formatter' require 'jsonapi/processor' require 'concurrent' diff --git a/lib/jsonapi/error.rb b/lib/jsonapi/error.rb index a5d878af8..12d65f585 100644 --- a/lib/jsonapi/error.rb +++ b/lib/jsonapi/error.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module JSONAPI class Error attr_accessor :title, :detail, :id, :href, :code, :source, :links, :status, :meta diff --git a/lib/jsonapi/error_codes.rb b/lib/jsonapi/error_codes.rb index d23f757c2..f25608413 100644 --- a/lib/jsonapi/error_codes.rb +++ b/lib/jsonapi/error_codes.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module JSONAPI VALIDATION_ERROR = '100' INVALID_RESOURCE = '101' diff --git a/lib/jsonapi/exceptions.rb b/lib/jsonapi/exceptions.rb index 0ed65e5a2..e917118cf 100644 --- a/lib/jsonapi/exceptions.rb +++ b/lib/jsonapi/exceptions.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module JSONAPI module Exceptions class Error < RuntimeError diff --git a/lib/jsonapi/formatter.rb b/lib/jsonapi/formatter.rb index 6f2922b57..7b79f931d 100644 --- a/lib/jsonapi/formatter.rb +++ b/lib/jsonapi/formatter.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module JSONAPI class Formatter class << self diff --git a/lib/jsonapi/include_directives.rb b/lib/jsonapi/include_directives.rb index a75b5adcd..2ad300133 100644 --- a/lib/jsonapi/include_directives.rb +++ b/lib/jsonapi/include_directives.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module JSONAPI class IncludeDirectives # Construct an IncludeDirectives Hash from an array of dot separated include strings. diff --git a/lib/jsonapi/link_builder.rb b/lib/jsonapi/link_builder.rb index 6ede8a022..d78f414e1 100644 --- a/lib/jsonapi/link_builder.rb +++ b/lib/jsonapi/link_builder.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module JSONAPI class LinkBuilder attr_reader :base_url, diff --git a/lib/jsonapi/mime_types.rb b/lib/jsonapi/mime_types.rb index 981998048..d888a1bd8 100644 --- a/lib/jsonapi/mime_types.rb +++ b/lib/jsonapi/mime_types.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'json' module JSONAPI diff --git a/lib/jsonapi/naive_cache.rb b/lib/jsonapi/naive_cache.rb index 53bf6ccb0..098300ba5 100644 --- a/lib/jsonapi/naive_cache.rb +++ b/lib/jsonapi/naive_cache.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module JSONAPI # Cache which memoizes the given block. diff --git a/lib/jsonapi/operation.rb b/lib/jsonapi/operation.rb index 3e6996a41..f87f6570f 100644 --- a/lib/jsonapi/operation.rb +++ b/lib/jsonapi/operation.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module JSONAPI class Operation attr_reader :resource_klass, :operation_type, :options diff --git a/lib/jsonapi/operation_result.rb b/lib/jsonapi/operation_result.rb index 1c9384273..63a3d9dc1 100644 --- a/lib/jsonapi/operation_result.rb +++ b/lib/jsonapi/operation_result.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module JSONAPI class OperationResult attr_accessor :code diff --git a/lib/jsonapi/paginator.rb b/lib/jsonapi/paginator.rb index 53f8fbbe4..1054354e4 100644 --- a/lib/jsonapi/paginator.rb +++ b/lib/jsonapi/paginator.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module JSONAPI class Paginator def initialize(_params) diff --git a/lib/jsonapi/path.rb b/lib/jsonapi/path.rb index ae111b49e..0e5d7e844 100644 --- a/lib/jsonapi/path.rb +++ b/lib/jsonapi/path.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module JSONAPI class Path attr_reader :segments, :resource_klass diff --git a/lib/jsonapi/path_segment.rb b/lib/jsonapi/path_segment.rb index e5cebd832..4b9879819 100644 --- a/lib/jsonapi/path_segment.rb +++ b/lib/jsonapi/path_segment.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module JSONAPI class PathSegment def self.parse(source_resource_klass:, segment_string:, parse_fields: true) diff --git a/lib/jsonapi/processor.rb b/lib/jsonapi/processor.rb index 88c455590..814642a45 100644 --- a/lib/jsonapi/processor.rb +++ b/lib/jsonapi/processor.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module JSONAPI class Processor include Callbacks diff --git a/lib/jsonapi/relationship.rb b/lib/jsonapi/relationship.rb index 6ed3c54b8..8824fc65d 100644 --- a/lib/jsonapi/relationship.rb +++ b/lib/jsonapi/relationship.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module JSONAPI class Relationship attr_reader :acts_as_set, :foreign_key, :options, :name, diff --git a/lib/jsonapi/request.rb b/lib/jsonapi/request.rb index 0c377d35e..5f250993f 100644 --- a/lib/jsonapi/request.rb +++ b/lib/jsonapi/request.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module JSONAPI class Request attr_accessor :fields, :include, :filters, :sort_criteria, :errors, :controller_module_path, diff --git a/lib/jsonapi/resource.rb b/lib/jsonapi/resource.rb index 0c09fb7e8..4d34dd290 100644 --- a/lib/jsonapi/resource.rb +++ b/lib/jsonapi/resource.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module JSONAPI class Resource < ActiveRelationResource root_resource diff --git a/lib/jsonapi/resource_controller.rb b/lib/jsonapi/resource_controller.rb index 0c3f7f345..70450d9d7 100644 --- a/lib/jsonapi/resource_controller.rb +++ b/lib/jsonapi/resource_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module JSONAPI class ResourceController < ActionController::Base include JSONAPI::ActsAsResourceController diff --git a/lib/jsonapi/resource_controller_metal.rb b/lib/jsonapi/resource_controller_metal.rb index f6f82e246..e8dfb3f55 100644 --- a/lib/jsonapi/resource_controller_metal.rb +++ b/lib/jsonapi/resource_controller_metal.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module JSONAPI class ResourceControllerMetal < ActionController::Metal MODULES = [ diff --git a/lib/jsonapi/resource_fragment.rb b/lib/jsonapi/resource_fragment.rb index 188e4caef..c42cf573d 100644 --- a/lib/jsonapi/resource_fragment.rb +++ b/lib/jsonapi/resource_fragment.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module JSONAPI # A ResourceFragment holds a ResourceIdentity and associated partial resource data. diff --git a/lib/jsonapi/resource_identity.rb b/lib/jsonapi/resource_identity.rb index 72635ecb4..baea3fcf8 100644 --- a/lib/jsonapi/resource_identity.rb +++ b/lib/jsonapi/resource_identity.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module JSONAPI # ResourceIdentity describes a unique identity of a resource in the system. diff --git a/lib/jsonapi/resource_serializer.rb b/lib/jsonapi/resource_serializer.rb index d3a03a631..731404f1e 100644 --- a/lib/jsonapi/resource_serializer.rb +++ b/lib/jsonapi/resource_serializer.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module JSONAPI class ResourceSerializer diff --git a/lib/jsonapi/resource_set.rb b/lib/jsonapi/resource_set.rb index 5cf6c6bbc..01fcdb77e 100644 --- a/lib/jsonapi/resource_set.rb +++ b/lib/jsonapi/resource_set.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module JSONAPI # Contains a hash of resource types which contain a hash of resources, relationships and primary status keyed by # resource id. diff --git a/lib/jsonapi/resource_tree.rb b/lib/jsonapi/resource_tree.rb index 0d8437f1c..a7a9a0b63 100644 --- a/lib/jsonapi/resource_tree.rb +++ b/lib/jsonapi/resource_tree.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module JSONAPI # A tree structure representing the resource structure of the requested resource(s). This is an intermediate structure diff --git a/lib/jsonapi/response_document.rb b/lib/jsonapi/response_document.rb index cc2ebba54..3558e5e0a 100644 --- a/lib/jsonapi/response_document.rb +++ b/lib/jsonapi/response_document.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module JSONAPI class ResponseDocument attr_reader :serialized_results diff --git a/lib/jsonapi/routing_ext.rb b/lib/jsonapi/routing_ext.rb index de6668a4b..b0b940138 100644 --- a/lib/jsonapi/routing_ext.rb +++ b/lib/jsonapi/routing_ext.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module ActionDispatch module Routing class Mapper