Skip to content

Commit

Permalink
Add deprecated attribute to element serializer
Browse files Browse the repository at this point in the history
Alchemy 5.2 introduced a new feature for the element definition.
Since the definition is just a hash we can safely use the attribute
on older versions as well.
  • Loading branch information
tvdeyen committed Jan 14, 2021
1 parent 91ff21d commit eb09e0e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
5 changes: 5 additions & 0 deletions app/serializers/alchemy/json_api/element_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ class ElementSerializer
:created_at,
:updated_at,
)

attribute :deprecated do |element|
!!definition["deprecated"]
end

belongs_to :parent_element, record_type: :element, serializer: self

belongs_to :page, record_type: :page, serializer: ::Alchemy::JsonApi::PageSerializer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
expect(subject[:created_at]).to eq(element.created_at)
expect(subject[:updated_at]).to eq(element.updated_at)
expect(subject[:position]).to eq(element.position)
expect(subject[:deprecated]).to eq(false)
expect(subject.keys).not_to include(:tag_list, :display_name)
end

Expand Down

0 comments on commit eb09e0e

Please sign in to comment.