Class: Plum::EntrySerializer
- Inherits:
-
Object
- Object
- Plum::EntrySerializer
- Defined in:
- app/services/plum/entry_serializer.rb
Instance Method Summary collapse
- #as_json(entry) ⇒ Object
-
#initialize(site:) ⇒ EntrySerializer
constructor
A new instance of EntrySerializer.
Constructor Details
#initialize(site:) ⇒ EntrySerializer
Returns a new instance of EntrySerializer.
3 4 5 6 |
# File 'app/services/plum/entry_serializer.rb', line 3 def initialize(site:) @site = site @expander = FieldExpander.new(site: site, url_builder: method(:entry_path)) end |
Instance Method Details
#as_json(entry) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'app/services/plum/entry_serializer.rb', line 8 def as_json(entry) { "id" => entry.id, "title" => entry.title, "slug" => entry.slug, "locale" => entry.locale, "url" => entry_path(entry), "status" => entry.status, "published_at" => entry.published_at&.iso8601, "updated_at" => entry.updated_at&.iso8601, "collection" => { "handle" => entry.content_type.handle, "title" => entry.content_type.name }, "data" => @expander.(values: entry.data, fields: entry.content_type.fields), "terms" => entry.terms.group_by { |term| term.taxonomy.handle }.transform_values do |terms| terms.map { |term| { "name" => term.name, "slug" => term.slug } } end } end |