Class: Occi::Core::Renderers::Json::Collection
- Defined in:
- lib/occi/core/renderers/json/collection.rb
Overview
Implements routines required to render ‘Occi::Core::Collection` and its subclasses to a JSON-based representation.
Constant Summary
Constants inherited from Base
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#ai_no_ent? ⇒ Boolean
:nodoc:.
-
#ent_no_ai? ⇒ Boolean
:nodoc:.
-
#render_action_instances_hash ⇒ Object
:nodoc:.
-
#render_entities_hash ⇒ Object
:nodoc:.
-
#render_hash ⇒ Object
:nodoc:.
Methods inherited from Base
Constructor Details
This class inherits a constructor from Occi::Core::Renderers::Json::Base
Instance Method Details
#ai_no_ent? ⇒ Boolean
:nodoc:
54 55 56 |
# File 'lib/occi/core/renderers/json/collection.rb', line 54 def ai_no_ent? object_action_instances.any? && object_entities.empty? end |
#ent_no_ai? ⇒ Boolean
:nodoc:
49 50 51 |
# File 'lib/occi/core/renderers/json/collection.rb', line 49 def ent_no_ai? object_entities.any? && object_action_instances.empty? end |
#render_action_instances_hash ⇒ Object
:nodoc:
41 42 43 44 45 46 |
# File 'lib/occi/core/renderers/json/collection.rb', line 41 def render_action_instances_hash if object_action_instances.count > 1 raise Occi::Core::Errors::RenderingError, 'Cannot render multiple action instances to JSON' end ActionInstance.new(object_action_instances.first, ).render_hash end |
#render_entities_hash ⇒ Object
:nodoc:
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/occi/core/renderers/json/collection.rb', line 29 def render_entities_hash hsh = {} if object_resources.any? hsh[:resources] = object_resources.collect { |r| Resource.new(r, ).render_hash } end if object_links.any? hsh[:links] = object_links.collect { |r| Link.new(r, ).render_hash } end hsh end |
#render_hash ⇒ Object
:nodoc:
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/occi/core/renderers/json/collection.rb', line 16 def render_hash return {} if object_empty? || object.only_categories? if ent_no_ai? render_entities_hash elsif ai_no_ent? render_action_instances_hash else raise Occi::Core::Errors::RenderingError, 'Cannot render mixed collection to JSON' end end |