From fbaba0ee8dc41927ad1eb9225b1186457672b130 Mon Sep 17 00:00:00 2001 From: Martin Meyerhoff Date: Mon, 16 Nov 2020 14:44:25 +0100 Subject: [PATCH] Fully qualify the names of Serializer classes There are naming conflicts with core Alchemy serializers that need to be resolved cleanly. This does that. --- app/serializers/alchemy/json_api/element_serializer.rb | 2 +- .../alchemy/json_api/essence_node_serializer.rb | 2 +- .../alchemy/json_api/essence_page_serializer.rb | 2 +- app/serializers/alchemy/json_api/language_serializer.rb | 6 +++--- app/serializers/alchemy/json_api/page_serializer.rb | 8 ++++---- lib/alchemy/json_api/essence_serializer.rb | 2 +- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/app/serializers/alchemy/json_api/element_serializer.rb b/app/serializers/alchemy/json_api/element_serializer.rb index 84aec20..0875966 100644 --- a/app/serializers/alchemy/json_api/element_serializer.rb +++ b/app/serializers/alchemy/json_api/element_serializer.rb @@ -12,7 +12,7 @@ class ElementSerializer ) belongs_to :parent_element, record_type: :element, serializer: self - belongs_to :page, record_type: :page, serializer: PageSerializer + belongs_to :page, record_type: :page, serializer: ::Alchemy::JsonApi::PageSerializer has_many :essences, polymorphic: true do |element| element.contents.map(&:essence) diff --git a/app/serializers/alchemy/json_api/essence_node_serializer.rb b/app/serializers/alchemy/json_api/essence_node_serializer.rb index 1204101..3cceb9b 100644 --- a/app/serializers/alchemy/json_api/essence_node_serializer.rb +++ b/app/serializers/alchemy/json_api/essence_node_serializer.rb @@ -10,7 +10,7 @@ class EssenceNodeSerializer essence&.node&.name end - belongs_to :node, record_type: :node, serializer: NodeSerializer + belongs_to :node, record_type: :node, serializer: ::Alchemy::JsonApi::NodeSerializer with_options if: proc { |essence| essence.node.present? } do attribute :name do |essence| diff --git a/app/serializers/alchemy/json_api/essence_page_serializer.rb b/app/serializers/alchemy/json_api/essence_page_serializer.rb index 11967bf..006741c 100644 --- a/app/serializers/alchemy/json_api/essence_page_serializer.rb +++ b/app/serializers/alchemy/json_api/essence_page_serializer.rb @@ -18,7 +18,7 @@ class EssencePageSerializer essence.page&.url_path end - has_one :page, record_type: :page, serializer: PageSerializer + has_one :page, record_type: :page, serializer: ::Alchemy::JsonApi::PageSerializer end end end diff --git a/app/serializers/alchemy/json_api/language_serializer.rb b/app/serializers/alchemy/json_api/language_serializer.rb index 7a4b3a5..eef2dd4 100644 --- a/app/serializers/alchemy/json_api/language_serializer.rb +++ b/app/serializers/alchemy/json_api/language_serializer.rb @@ -10,13 +10,13 @@ class LanguageSerializer :locale, ) - has_many :menu_items, record_type: :node, serializer: NodeSerializer, object_method_name: :nodes, id_method_name: :node_ids + has_many :menu_items, record_type: :node, serializer: ::Alchemy::JsonApi::NodeSerializer, object_method_name: :nodes, id_method_name: :node_ids - has_many :menus, record_type: :node, serializer: NodeSerializer do |language| + has_many :menus, record_type: :node, serializer: ::Alchemy::JsonApi::NodeSerializer do |language| language.nodes.select { |n| n.parent.nil? } end has_many :pages - has_one :root_page, record_type: :page, serializer: PageSerializer + has_one :root_page, record_type: :page, serializer: ::Alchemy::JsonApi::PageSerializer with_options if: ->(_, params) { params[:admin] == true } do attribute :created_at diff --git a/app/serializers/alchemy/json_api/page_serializer.rb b/app/serializers/alchemy/json_api/page_serializer.rb index b080a29..11d292a 100644 --- a/app/serializers/alchemy/json_api/page_serializer.rb +++ b/app/serializers/alchemy/json_api/page_serializer.rb @@ -15,12 +15,12 @@ class PageSerializer :updated_at, ) - belongs_to :language, record_type: :language, serializer: LanguageSerializer + belongs_to :language, record_type: :language, serializer: ::Alchemy::JsonApi::LanguageSerializer - has_many :elements, record_type: :element, serializer: ElementSerializer - has_many :fixed_elements, record_type: :element, serializer: ElementSerializer + has_many :elements, record_type: :element, serializer: ::Alchemy::JsonApi::ElementSerializer + has_many :fixed_elements, record_type: :element, serializer: ::Alchemy::JsonApi::ElementSerializer - has_many :all_elements, record_type: :element, serializer: ElementSerializer do |page| + has_many :all_elements, record_type: :element, serializer: ::Alchemy::JsonApi::ElementSerializer do |page| page.all_elements.select { |e| e.public? && !e.trashed? } end diff --git a/lib/alchemy/json_api/essence_serializer.rb b/lib/alchemy/json_api/essence_serializer.rb index f66bbe1..ff5c5e6 100644 --- a/lib/alchemy/json_api/essence_serializer.rb +++ b/lib/alchemy/json_api/essence_serializer.rb @@ -4,7 +4,7 @@ module JsonApi module EssenceSerializer def self.included(klass) klass.include FastJsonapi::ObjectSerializer - klass.has_one :element, record_type: :element, serializer: ElementSerializer do |essence| + klass.has_one :element, record_type: :element, serializer: ::Alchemy::JsonApi::ElementSerializer do |essence| essence.content.element end klass.attributes :ingredient