module Serega::SeregaPlugins::Metadata::ClassMethods
Class methods the plugin adds to serializers
Public Instance Methods
(*Symbol | String path, **untyped opts) ?{ (untyped objects, context context) → untyped } → void
Source
# File lib/serega/plugins/metadata/metadata.rb, line 51 def meta_attribute(*path, **opts, &block) check_unlocked attribute = MetaAttribute.new(self, path: path, opts: opts, block: block) meta_attributes[attribute.name] = attribute end
Adds metadata under a path of keys. The value is const:, a value: callable or a block, which receive the serialized objects and the context. hide_nil: true skips nil values, hide_empty: true skips nil and empty values.
meta_attribute :meta, :paging, hide_nil: true do |records, ctx| next unless records.respond_to?(:total_count) {page: records.current_page, total_count: records.total_count} end