Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fully qualify the names of Serializer classes #18

Merged
merged 1 commit into from
Nov 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/serializers/alchemy/json_api/element_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions app/serializers/alchemy/json_api/language_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions app/serializers/alchemy/json_api/page_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion lib/alchemy/json_api/essence_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down