mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-22 22:06:50 +00:00
26 lines
515 B
Ruby
26 lines
515 B
Ruby
module ActiveModel
|
|
module Serializable
|
|
def as_json(options={})
|
|
if root = options.fetch(:root, json_key)
|
|
hash = { root => serializable_object }
|
|
hash.merge!(serializable_data)
|
|
hash
|
|
else
|
|
serializable_object
|
|
end
|
|
end
|
|
|
|
def serializable_data
|
|
embedded_in_root_associations.tap do |hash|
|
|
if respond_to?(:meta) && meta
|
|
hash[meta_key] = meta
|
|
end
|
|
end
|
|
end
|
|
|
|
def embedded_in_root_associations
|
|
{}
|
|
end
|
|
end
|
|
end
|