mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 07:16:49 +00:00
Add support for meta key
Test for meta_key serialization
This commit is contained in:
@@ -227,6 +227,14 @@ module ActiveModel
|
||||
@options[:url_options] || {}
|
||||
end
|
||||
|
||||
def meta_key
|
||||
@options[:meta_key].try(:to_sym) || :meta
|
||||
end
|
||||
|
||||
def include_meta(hash)
|
||||
hash[meta_key] = @options[:meta] if @options.has_key?(:meta)
|
||||
end
|
||||
|
||||
# Returns a json representation of the serializable
|
||||
# object including the root.
|
||||
def as_json(options={})
|
||||
@@ -235,6 +243,7 @@ module ActiveModel
|
||||
@options[:unique_values] = {}
|
||||
|
||||
hash.merge!(root => serializable_hash)
|
||||
include_meta hash
|
||||
hash
|
||||
else
|
||||
serializable_hash
|
||||
|
||||
Reference in New Issue
Block a user