Module: Serega::SeregaPlugins::Metadata::ClassMethods

Defined in:
lib/serega/plugins/metadata/metadata.rb

Instance Method Summary collapse

Instance Method Details

#meta_attribute(*path, **opts, &block) ⇒ MetadataAttribute

Adds metadata to response

Examples:

class AppSerializer < Serega

  meta_attribute(:version) { '1.2.3' }

  meta_attribute(:meta, :paging, hide_nil: true, hide_empty: true) do |scope, ctx|
    { page: scope.page, per_page: scope.per_page, total_count: scope.total_count }
  end
end

Parameters:

  • *path (Array<String, Symbol>)

    Metadata attribute path keys

  • **opts (Hash)

    Metadata attribute options

  • &block (Proc)

    Metadata attribute value

Returns:

  • (MetadataAttribute)

    Added metadata attribute



101
102
103
104
# File 'lib/serega/plugins/metadata/metadata.rb', line 101

def meta_attribute(*path, **opts, &block)
  attribute = self::MetaAttribute.new(path: path, opts: opts, block: block)
  meta_attributes[attribute.name] = attribute
end

#meta_attributesArray

List of added metadata attributes

Returns:

  • (Array)

    Added metadata attributes



78
79
80
# File 'lib/serega/plugins/metadata/metadata.rb', line 78

def meta_attributes
  @meta_attributes ||= {}
end