class Shaf::ALPS::JsonSerializer

Constants

ALPS_VERSION

Attributes

profile[R]

Public Class Methods

call(profile) click to toggle source
# File lib/shaf/alps/json_serializer.rb, line 11
def self.call(profile)
  new(profile).to_hash
end
new(profile) click to toggle source
# File lib/shaf/alps/json_serializer.rb, line 17
def initialize(profile)
  @profile = profile
end

Public Instance Methods

to_hash() click to toggle source
# File lib/shaf/alps/json_serializer.rb, line 21
def to_hash
  {
    alps: {
      version: ALPS_VERSION,
      doc: profile.doc,
      descriptor: descriptors,
    }.compact
  }
end

Private Instance Methods

attribute_descriptors() click to toggle source
# File lib/shaf/alps/json_serializer.rb, line 37
def attribute_descriptors
  profile.attributes.map do |desc|
    AttributeSerializer.call(desc)
  end
end
descriptors() click to toggle source
# File lib/shaf/alps/json_serializer.rb, line 33
def descriptors
  attribute_descriptors + relation_descriptors
end
relation_descriptors() click to toggle source
# File lib/shaf/alps/json_serializer.rb, line 43
def relation_descriptors
  profile.relations.map do |desc|
    RelationSerializer.call(desc)
  end
end