class Occi::Core::Parsers::Json::ActionInstance

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

@author Boris Parak <parak@cesnet.cz>

Constants

DELEGATED

Shortcuts to interesting methods on logger

Public Class Methods

json(body, model) click to toggle source

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

@param body [String] JSON body for parsing @param model [Occi::Core::Model] model with existing categories @return [Occi::Core::ActionInstance] action instance

# 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