Class: Occi::Core::Renderers::Text::Base
- Inherits:
-
Object
- Object
- Occi::Core::Renderers::Text::Base
- 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.
Direct Known Subclasses
ActionInstance, Attributes, Category, Link, Locations, Model, Resource
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
-
#object ⇒ Object
instance to be rendered.
-
#options ⇒ Hash
additional rendering options.
Class Method Summary collapse
-
.render_safe ⇒ Integer
Returns an acceptable value for the $SAFE env variable that should be enforced when evaluating templates.
Instance Method Summary collapse
-
#initialize(object, options) ⇒ Base
constructor
Constructs a renderer instance for the given object.
-
#render ⇒ String, Hash
Renders the given object to ‘text`.
-
#render_safe ⇒ Integer
Returns an acceptable value for the $SAFE env variable that should be enforced when evaluating templates.
Constructor Details
#initialize(object, options) ⇒ Base
Constructs a renderer instance for the given object.
30 31 32 33 |
# File 'lib/occi/core/renderers/text/base.rb', line 30 def initialize(object, ) @object = object @options = end |
Instance Attribute Details
#object ⇒ Object
instance to be rendered
13 14 15 |
# File 'lib/occi/core/renderers/text/base.rb', line 13 def object @object end |
#options ⇒ Hash
additional rendering options
13 14 15 |
# File 'lib/occi/core/renderers/text/base.rb', line 13 def @options end |
Class Method Details
.render_safe ⇒ Integer
Returns an acceptable value for the $SAFE env variable that should be enforced when evaluating templates.
64 65 66 |
# File 'lib/occi/core/renderers/text/base.rb', line 64 def render_safe RENDER_SAFE end |
Instance Method Details
#render ⇒ String, Hash
Renders the given object to ‘text`.
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/occi/core/renderers/text/base.rb', line 39 def render case [:format] when 'text', 'text_plain' render_plain when 'headers', 'text_occi' render_headers else raise Occi::Core::Errors::RenderingError, "Rendering to #{[:format]} is not supported" end end |
#render_safe ⇒ Integer
Returns an acceptable value for the $SAFE env variable that should be enforced when evaluating templates.
55 56 57 |
# File 'lib/occi/core/renderers/text/base.rb', line 55 def render_safe RENDER_SAFE end |