Class: Occi::Core::Renderers::Text::Base

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

Overview

Implements methods common to all text-based renderers. This class is not meant to be used directly, only as a parent to other type-specific rendering classes.

Author:

Constant Summary collapse

RENDER_SAFE =

Ruby 2.3 compatibility, with `$SAFE` changes

RUBY_VERSION >= '2.3' ? 1 : 3
DELEGATED =

Shortcuts to interesting object attributes, always prefixed with `object_`

%i[send empty? categories entities resources links action_instances].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object, options) ⇒ Base

Constructs a renderer instance for the given object.

Parameters:

  • object (Object)

    instance to be rendered

  • options (Hash)

    additional options


30
31
32
33
# File 'lib/occi/core/renderers/text/base.rb', line 30

def initialize(object, options)
  @object = object
  @options = options
end

Instance Attribute Details

#objectObject

instance to be rendered

Returns:

  • (Object)

    the current value of object


13
14
15
# File 'lib/occi/core/renderers/text/base.rb', line 13

def object
  @object
end

#optionsHash

additional rendering options

Returns:

  • (Hash)

    the current value of options


13
14
15
# File 'lib/occi/core/renderers/text/base.rb', line 13

def options
  @options
end

Class Method Details

.render_safeInteger

Returns an acceptable value for the $SAFE env variable that should be enforced when evaluating templates.

Returns:

  • (Integer)

    SAFE level


64
65
66
# File 'lib/occi/core/renderers/text/base.rb', line 64

def render_safe
  RENDER_SAFE
end

Instance Method Details

#renderString, Hash

Renders the given object to `text`.

Returns:

  • (String)

    object rendering as plain text

  • (Hash)

    object rendering as hash


39
40
41
42
43
44
45
46
47
48
49
# File 'lib/occi/core/renderers/text/base.rb', line 39

def render
  case options[:format]
  when 'text', 'text_plain'
    render_plain
  when 'headers', 'text_occi'
    render_headers
  else
    raise Occi::Core::Errors::RenderingError,
          "Rendering to #{options[:format]} is not supported"
  end
end

#render_safeInteger

Returns an acceptable value for the $SAFE env variable that should be enforced when evaluating templates.

Returns:

  • (Integer)

    SAFE level


55
56
57
# File 'lib/occi/core/renderers/text/base.rb', line 55

def render_safe
  RENDER_SAFE
end