Class: Occi::Core::Renderers::BaseRenderer Abstract

Inherits:
Object
  • Object
show all
Includes:
Yell::Loggable
Defined in:
lib/occi/core/renderers/base_renderer.rb

Overview

This class is abstract.

Not for direct use.

Implementes components common to all rendereres. It is not intended for direct use.

Author:

Direct Known Subclasses

JsonRenderer, TextRenderer

Class Method Summary collapse

Class Method Details

.formatsArray

Returns a list of formats supported by this renderer. Formats are compliant with method naming restrictions and String-like.

Returns:

  • (Array)

    list of formats


24
25
26
# File 'lib/occi/core/renderers/base_renderer.rb', line 24

def formats
  []
end

.knownArray

Returns a frozen Hash providing mapping information between supported types and supported serializers.

Returns:

  • (Array)

    list of known type->serializer mappings


66
67
68
# File 'lib/occi/core/renderers/base_renderer.rb', line 66

def known
  {}
end

.known_serializersArray

Returns the list of known (and supported) serializer classes. Every element in the list is a fully namespaced classes.

Returns:

  • (Array)

    list of known serializers


58
59
60
# File 'lib/occi/core/renderers/base_renderer.rb', line 58

def known_serializers
  known.values
end

.known_typesArray

Returns the list of known (and supported) types for serialization. Every element in the list is a string representing a fully namespaced class name.

Returns:

  • (Array)

    list of known types


50
51
52
# File 'lib/occi/core/renderers/base_renderer.rb', line 50

def known_types
  known.keys
end

.render(object, options) ⇒ String

Renders the given `object` into a rendering in `options`.

Parameters:

  • object (Object)

    instance to be rendered

  • options (Hash)

    additional rendering options

Options Hash (options):

  • :format (String) — default: nil

    rendering (sub)type

Returns:

  • (String)

    object rendering


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

def render(object, options)
  logger.debug "#{self} rendering #{object.inspect} with #{options.inspect}"
  candidate = rendering_candidate(object)
  unless candidate
    raise Occi::Core::Errors::RenderingError, "#{object.class} cannot be " \
          "rendered to #{options[:format]}"
  end

  known[candidate].new(object, options).render
end

.renderer?TrueClass, FalseClass

Indicates whether this class is a renderer candidate.

Returns:


15
16
17
# File 'lib/occi/core/renderers/base_renderer.rb', line 15

def renderer?
  false
end