Class: Shaf::Serializer

Inherits:
Object
  • Object
show all
Extended by:
HALPresenter, UriHelper
Defined in:
lib/shaf/serializer.rb

Overview

A base class used for serializing objects into a HAL representations.

Class Attribute Summary collapse

Class Method Summary collapse

Methods included from UriHelper

base_uri, included

Methods included from UriHelperMethods

add_path_helpers, eval_method, path_helpers, #path_helpers, path_helpers_for, register, remove_all

Class Attribute Details

.default_curie_prefixObject (readonly)

Returns the value of attribute default_curie_prefix.



12
13
14
# File 'lib/shaf/serializer.rb', line 12

def default_curie_prefix
  @default_curie_prefix
end

Class Method Details

.profile(name, curie_prefix: :doc) ⇒ Object

Creates a link with rel profile and href pointing to the corresponding profile. It also adds a Curie link.

Parameters:

  • name (String)

    the name of the profile

  • curie_prefix (Symbol) (defaults to: :doc)

    the prefix used for the Curie



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/shaf/serializer.rb', line 18

def profile(name, curie_prefix: :doc)
  profile = Profiles.find name

  super { profile&.urn || profile_uri(name) }

  link :profile do
    profile_uri(name)
  end

  curie curie_prefix do
    doc_curie_uri(name)
  end

  @default_curie_prefix = curie_prefix.to_sym
end