Class: Occi::Core::Renderers::Text::Resource

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

Overview

Implements methods needed to render resource instances to text-based renderings. This class (its instances) is usually called directly from the “outside”. It utilizes `Category` and `Attributes` from this module to render kind, mixins, and instance attributes.

Author:

Constant Summary collapse

'Link'.freeze
'X-OCCI-Link'.freeze

Constants inherited from Base

Base::DELEGATED, Base::RENDER_SAFE

Instance Attribute Summary

Attributes inherited from Base

#object, #options

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#initialize, #render, #render_safe, render_safe

Constructor Details

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

Class Method Details

.action_templateObject

:nodoc:


92
93
94
# File 'lib/occi/core/renderers/text/resource.rb', line 92

def action_template
  '<<%= object.location %>?action=<%= action.term %>>; rel="<%= action %>"'
end

:nodoc:


97
98
99
100
101
102
103
# File 'lib/occi/core/renderers/text/resource.rb', line 97

def link_template
  '<<%= link.target %>>; ' \
  'rel="<%= link.rel %>"; ' \
  'self="<%= link.location %>"; ' \
  'category="<%= link_categories %>"; ' \
  '<%= link_attributes %>'
end

Instance Method Details

#render_headersHash

Renders `object` into text for headers and returns the result as `Hash`.


36
37
38
39
40
41
42
43
44
45
# File 'lib/occi/core/renderers/text/resource.rb', line 36

def render_headers
  headers = short_category(object.kind)
  headers[Category.category_key_headers].concat(
    short_mixins_headers
  )
  headers.merge!(instance_attributes)
  headers.merge!(header_links)

  headers
end

#render_plainString

Renders `object` into plain text and returns the result as `String`.


25
26
27
28
29
30
# File 'lib/occi/core/renderers/text/resource.rb', line 25

def render_plain
  [
    short_category(object.kind), short_mixins_plain, instance_attributes,
    instance_links, instance_actions
  ].flatten.join("\n")
end