Class: Occi::Core::Parsers::Json::ActionInstance

Inherits:
Object
  • Object
show all
Extended by:
Helpers::RawJsonParser
Includes:
Helpers::ErrorHandler, Yell::Loggable
Defined in:
lib/occi/core/parsers/json/action_instance.rb

Overview

Static parsing class responsible for extracting action instances from JSON. Class supports 'application/json' via `json`. No other formats are supported.

Author:

Constant Summary collapse

DELEGATED =

Shortcuts to interesting methods on logger

%i[debug? info? warn? error? fatal?].freeze

Class Method Summary collapse

Methods included from Helpers::RawJsonParser

raw_hash

Methods included from Helpers::ErrorHandler

#handle, included

Class Method Details

.json(body, model) ⇒ Occi::Core::ActionInstance

Parses action instances. Internal references between objects are converted from strings to actual objects. Actions have to be declared in the provided model.


25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/occi/core/parsers/json/action_instance.rb', line 25

def json(body, model)
  parsed = raw_hash(body)
  action = handle(Occi::Core::Errors::ParsingError) { model.find_by_identifier! parsed[:action] }

  logger.debug "Identified #{action.class}[#{action.identifier}]"
  ai = Occi::Core::ActionInstance.new(action: action)
  ep = Entity.new(model: model)
  ep.set_attributes!(ai, parsed[:attributes]) if parsed[:attributes]

  logger.debug "Parsed into ActionInstance #{ai.inspect}" if logger_debug?
  ai
end