Skip to content

Commit

Permalink
add frozen_string_literal magic comment (#1408)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
yawboakye authored Sep 18, 2023
1 parent 0ba80a1 commit a2e8ad5
Show file tree
Hide file tree
Showing 34 changed files with 68 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/jsonapi-resources.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'jsonapi/resources/railtie'
require 'jsonapi/naive_cache'
require 'jsonapi/compiled_json'
Expand Down
2 changes: 2 additions & 0 deletions lib/jsonapi/active_relation_resource.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module JSONAPI
class ActiveRelationResource < BasicResource
root_resource
Expand Down
2 changes: 2 additions & 0 deletions lib/jsonapi/acts_as_resource_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'csv'

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

require 'jsonapi/callbacks'
require 'jsonapi/configuration'

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

module JSONAPI
class CachedResponseFragment

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

require 'active_support/callbacks'

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

module JSONAPI
class CompiledJson
def self.compile(h)
Expand Down
2 changes: 2 additions & 0 deletions lib/jsonapi/configuration.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'jsonapi/formatter'
require 'jsonapi/processor'
require 'concurrent'
Expand Down
2 changes: 2 additions & 0 deletions lib/jsonapi/error.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module JSONAPI
class Error
attr_accessor :title, :detail, :id, :href, :code, :source, :links, :status, :meta
Expand Down
2 changes: 2 additions & 0 deletions lib/jsonapi/error_codes.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module JSONAPI
VALIDATION_ERROR = '100'
INVALID_RESOURCE = '101'
Expand Down
2 changes: 2 additions & 0 deletions lib/jsonapi/exceptions.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module JSONAPI
module Exceptions
class Error < RuntimeError
Expand Down
2 changes: 2 additions & 0 deletions lib/jsonapi/formatter.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module JSONAPI
class Formatter
class << self
Expand Down
2 changes: 2 additions & 0 deletions lib/jsonapi/include_directives.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module JSONAPI
class IncludeDirectives
# Construct an IncludeDirectives Hash from an array of dot separated include strings.
Expand Down
2 changes: 2 additions & 0 deletions lib/jsonapi/link_builder.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module JSONAPI
class LinkBuilder
attr_reader :base_url,
Expand Down
2 changes: 2 additions & 0 deletions lib/jsonapi/mime_types.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'json'

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

module JSONAPI

# Cache which memoizes the given block.
Expand Down
2 changes: 2 additions & 0 deletions lib/jsonapi/operation.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module JSONAPI
class Operation
attr_reader :resource_klass, :operation_type, :options
Expand Down
2 changes: 2 additions & 0 deletions lib/jsonapi/operation_result.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module JSONAPI
class OperationResult
attr_accessor :code
Expand Down
2 changes: 2 additions & 0 deletions lib/jsonapi/paginator.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module JSONAPI
class Paginator
def initialize(_params)
Expand Down
2 changes: 2 additions & 0 deletions lib/jsonapi/path.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module JSONAPI
class Path
attr_reader :segments, :resource_klass
Expand Down
2 changes: 2 additions & 0 deletions lib/jsonapi/path_segment.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module JSONAPI
class PathSegment
def self.parse(source_resource_klass:, segment_string:, parse_fields: true)
Expand Down
2 changes: 2 additions & 0 deletions lib/jsonapi/processor.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module JSONAPI
class Processor
include Callbacks
Expand Down
2 changes: 2 additions & 0 deletions lib/jsonapi/relationship.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module JSONAPI
class Relationship
attr_reader :acts_as_set, :foreign_key, :options, :name,
Expand Down
2 changes: 2 additions & 0 deletions lib/jsonapi/request.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module JSONAPI
class Request
attr_accessor :fields, :include, :filters, :sort_criteria, :errors, :controller_module_path,
Expand Down
2 changes: 2 additions & 0 deletions lib/jsonapi/resource.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module JSONAPI
class Resource < ActiveRelationResource
root_resource
Expand Down
2 changes: 2 additions & 0 deletions lib/jsonapi/resource_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module JSONAPI
class ResourceController < ActionController::Base
include JSONAPI::ActsAsResourceController
Expand Down
2 changes: 2 additions & 0 deletions lib/jsonapi/resource_controller_metal.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module JSONAPI
class ResourceControllerMetal < ActionController::Metal
MODULES = [
Expand Down
2 changes: 2 additions & 0 deletions lib/jsonapi/resource_fragment.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module JSONAPI

# A ResourceFragment holds a ResourceIdentity and associated partial resource data.
Expand Down
2 changes: 2 additions & 0 deletions lib/jsonapi/resource_identity.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module JSONAPI

# ResourceIdentity describes a unique identity of a resource in the system.
Expand Down
2 changes: 2 additions & 0 deletions lib/jsonapi/resource_serializer.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module JSONAPI
class ResourceSerializer

Expand Down
2 changes: 2 additions & 0 deletions lib/jsonapi/resource_set.rb
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 2 additions & 0 deletions lib/jsonapi/resource_tree.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 2 additions & 0 deletions lib/jsonapi/response_document.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module JSONAPI
class ResponseDocument
attr_reader :serialized_results
Expand Down
2 changes: 2 additions & 0 deletions lib/jsonapi/routing_ext.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module ActionDispatch
module Routing
class Mapper
Expand Down

0 comments on commit a2e8ad5

Please sign in to comment.