diff --git a/.rubocop.yml b/.rubocop.yml index 50263f3..25104f3 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -2,6 +2,10 @@ require: - rubocop-performance - rubocop-rspec +AllCops: + NewCops: enable + SuggestExtensions: false + Style/FrozenStringLiteralComment: Enabled: false @@ -76,3 +80,20 @@ Naming/PredicateName: Naming/AccessorMethodName: Exclude: - 'lib/**/**.rb' + +Style/CaseLikeIf: + Exclude: + - 'lib/fast_jsonapi/object_serializer.rb' + +Style/OptionalBooleanParameter: + Exclude: + - 'lib/fast_jsonapi/serialization_core.rb' + - 'lib/fast_jsonapi/relationship.rb' + +Lint/DuplicateBranch: + Exclude: + - 'lib/fast_jsonapi/relationship.rb' + +Style/DocumentDynamicEvalDefinition: + Exclude: + - 'lib/extensions/has_one.rb' diff --git a/lib/fast_jsonapi/object_serializer.rb b/lib/fast_jsonapi/object_serializer.rb index 874b7be..26dd5f5 100644 --- a/lib/fast_jsonapi/object_serializer.rb +++ b/lib/fast_jsonapi/object_serializer.rb @@ -228,10 +228,10 @@ module FastJsonapi # TODO: Remove this undocumented option. # Delegate the caching to the serializer exclusively. - if !relationship.cached - uncachable_relationships_to_serialize[relationship.name] = relationship - else + if relationship.cached cachable_relationships_to_serialize[relationship.name] = relationship + else + uncachable_relationships_to_serialize[relationship.name] = relationship end relationships_to_serialize[relationship.name] = relationship end @@ -302,7 +302,7 @@ module FastJsonapi def serializer_for(name) namespace = self.name.gsub(/()?\w+Serializer$/, '') - serializer_name = name.to_s.demodulize.classify + 'Serializer' + serializer_name = "#{name.to_s.demodulize.classify}Serializer" serializer_class_name = namespace + serializer_name begin serializer_class_name.constantize @@ -340,7 +340,7 @@ module FastJsonapi def validate_includes!(includes) return if includes.blank? - parse_includes_list(includes).keys.each do |include_item| + parse_includes_list(includes).each_key do |include_item| relationship_to_include = relationships_to_serialize[include_item] raise(JSONAPI::Serializer::UnsupportedIncludeError.new(include_item, name)) unless relationship_to_include diff --git a/lib/fast_jsonapi/relationship.rb b/lib/fast_jsonapi/relationship.rb index cc26d70..4a36932 100644 --- a/lib/fast_jsonapi/relationship.rb +++ b/lib/fast_jsonapi/relationship.rb @@ -12,7 +12,12 @@ module FastJsonapi object_block:, serializer:, relationship_type:, - polymorphic:, conditional_proc:, transform_method:, links:, meta:, cached: false, + polymorphic:, + conditional_proc:, + transform_method:, + links:, + meta:, + cached: false, lazy_load_data: false ) @owner = owner diff --git a/lib/jsonapi/serializer/errors.rb b/lib/jsonapi/serializer/errors.rb index 7272eec..0faca6f 100644 --- a/lib/jsonapi/serializer/errors.rb +++ b/lib/jsonapi/serializer/errors.rb @@ -8,6 +8,7 @@ module JSONAPI attr_reader :include_item, :klass def initialize(include_item, klass) + super() @include_item = include_item @klass = klass end diff --git a/spec/fixtures/movie.rb b/spec/fixtures/movie.rb index a8a086d..f99af21 100644 --- a/spec/fixtures/movie.rb +++ b/spec/fixtures/movie.rb @@ -26,7 +26,7 @@ class Movie @url ||= FFaker::Internet.http_url return @url if obj.nil? - @url + '?' + obj.hash.to_s + "#{@url}?#{obj.hash}" end def owner=(ownr) diff --git a/spec/integration/instrumentation_spec.rb b/spec/integration/instrumentation_spec.rb index 59ad425..1a106ee 100644 --- a/spec/integration/instrumentation_spec.rb +++ b/spec/integration/instrumentation_spec.rb @@ -10,10 +10,8 @@ RSpec.describe JSONAPI::Serializer do it do payload = event_name = nil - notification_name = ( - ::JSONAPI::Serializer::Instrumentation::NOTIFICATION_NAMESPACE + - 'serializable_hash' - ) + notification_name = + "#{::JSONAPI::Serializer::Instrumentation::NOTIFICATION_NAMESPACE}serializable_hash" ActiveSupport::Notifications.subscribe( notification_name