mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 07:16:49 +00:00
Add docs to serializable
This commit is contained in:
parent
aaa08c25ef
commit
f179a27ed7
@ -1,4 +1,27 @@
|
|||||||
|
require 'active_support/core_ext/object/to_json'
|
||||||
|
|
||||||
module ActiveModel
|
module ActiveModel
|
||||||
|
# Enable classes to Classes including this module to serialize themselves by implementing a serialize method and an options method.
|
||||||
|
#
|
||||||
|
# Example:
|
||||||
|
#
|
||||||
|
# require 'active_model_serializers'
|
||||||
|
#
|
||||||
|
# class MySerializer
|
||||||
|
# include ActiveModel::Serializable
|
||||||
|
#
|
||||||
|
# def initialize
|
||||||
|
# @options = {}
|
||||||
|
# end
|
||||||
|
#
|
||||||
|
# attr_reader :options
|
||||||
|
#
|
||||||
|
# def serialize
|
||||||
|
# { a: 1 }
|
||||||
|
# end
|
||||||
|
# end
|
||||||
|
#
|
||||||
|
# puts MySerializer.new.to_json
|
||||||
module Serializable
|
module Serializable
|
||||||
def as_json(args={})
|
def as_json(args={})
|
||||||
if root = args[:root] || options[:root]
|
if root = args[:root] || options[:root]
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user