Class: ActionFigure::Formatters::JsonApi::Resource

Inherits:
Object
  • Object
show all
Defined in:
lib/action_figure/formatters/json_api/resource.rb

Overview

Simple resource serialization

Class Method Summary collapse

Class Method Details

.serialize(resource) ⇒ Object



8
9
10
11
12
13
14
15
16
# File 'lib/action_figure/formatters/json_api/resource.rb', line 8

def self.serialize(resource)
  if resource.respond_to?(:attributes)
    serialize_one(resource)
  elsif !resource.is_a?(Hash) && resource.respond_to?(:each)
    resource.map { |r| serialize(r) }
  else
    resource
  end
end