Class: Occi::Core::Renderers::Json::Link

Inherits:
Base
  • Object
show all
Includes:
Instance
Defined in:
lib/occi/core/renderers/json/link.rb

Overview

Implements routines required to render `Occi::Core::Link` and its subclasses to a JSON-based representation.

Author:

Constant Summary collapse

COMPUTE_KIND =

TODO: this is a hack for typing `source` on known Compute links

'http://schemas.ogf.org/occi/infrastructure#compute'.freeze
%w[
  http://schemas.ogf.org/occi/infrastructure#networkinterface
  http://schemas.ogf.org/occi/infrastructure#storagelink
  http://schemas.ogf.org/occi/infrastructure#securitygrouplink
].freeze

Constants inherited from Base

Base::DELEGATED

Instance Attribute Summary

Attributes inherited from Base

#object, #options

Instance Method Summary collapse

Methods included from Instance

#render_attributes_hash, #render_instance_hash

Methods inherited from Base

#initialize, #render

Constructor Details

This class inherits a constructor from Occi::Core::Renderers::Json::Base

Instance Method Details

#render_hashObject

:nodoc:


24
25
26
27
28
29
# File 'lib/occi/core/renderers/json/link.rb', line 24

def render_hash
  base = render_instance_hash
  base[:source] = typed_uri_hash(object_source, :source) if object_source
  base[:target] = typed_uri_hash(object_target, :target) if object_target
  base
end

#typed_uri_hash(attribute, type) ⇒ Object

:nodoc:


32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/occi/core/renderers/json/link.rb', line 32

def typed_uri_hash(attribute, type)
  hsh = { location: attribute.to_s }

  if type == :target && object_respond_to?(:rel)
    hsh[:kind] = object_rel.to_s
  elsif type == :source && COMPUTY_LINKS.include?(object_kind.to_s)
    # TODO: fix this mess
    hsh[:kind] = COMPUTE_KIND
  end

  hsh
end