Class: ActiveModel::Serializer
- Inherits:
-
Object
- Object
- ActiveModel::Serializer
- Defined in:
- lib/oj_serializers/compat.rb
Overview
Extensions: To ensure JsonStringEncoder can process ActiveModel::Serializer as well.
Defined Under Namespace
Modules: OjOptionsCompat
Class Method Summary collapse
-
.many(array, options = nil) ⇒ Object
JsonStringEncoder: Used internally to write an array of objects to JSON.
-
.many_as_hash(array) ⇒ Object
OjSerializer: Used internally to write an association in :hash mode.
-
.one(object, options = nil) ⇒ Object
JsonStringEncoder: Used internally to write a single object to JSON.
-
.one_as_hash(object) ⇒ Object
OjSerializer: Used internally to write a single object association in :hash mode.
-
.write_many(writer, array) ⇒ Object
OjSerializer: Used internally to write an association in :json mode.
-
.write_one(writer, object) ⇒ Object
OjSerializer: Used internally to write a single object association in :json mode.
Class Method Details
.many(array, options = nil) ⇒ Object
JsonStringEncoder: Used internally to write an array of objects to JSON.
14 15 16 |
# File 'lib/oj_serializers/compat.rb', line 14 def self.many(array, = nil) array.map { |object| new(object, ) } end |
.many_as_hash(array) ⇒ Object
OjSerializer: Used internally to write an association in :hash mode.
Returns nothing.
28 29 30 |
# File 'lib/oj_serializers/compat.rb', line 28 def self.many_as_hash(array) array.map { |object| new(object) } end |
.one(object, options = nil) ⇒ Object
JsonStringEncoder: Used internally to write a single object to JSON.
9 10 11 |
# File 'lib/oj_serializers/compat.rb', line 9 def self.one(object, = nil) new(object, ) end |
.one_as_hash(object) ⇒ Object
OjSerializer: Used internally to write a single object association in :hash mode.
Returns nothing.
21 22 23 |
# File 'lib/oj_serializers/compat.rb', line 21 def self.one_as_hash(object) new(object) end |
.write_many(writer, array) ⇒ Object
OjSerializer: Used internally to write an association in :json mode.
Returns nothing.
42 43 44 45 46 47 48 |
# File 'lib/oj_serializers/compat.rb', line 42 def self.write_many(writer, array) writer.push_array array.each do |object| write_one(writer, object) end writer.pop end |
.write_one(writer, object) ⇒ Object
OjSerializer: Used internally to write a single object association in :json mode.
Returns nothing.
35 36 37 |
# File 'lib/oj_serializers/compat.rb', line 35 def self.write_one(writer, object) writer.push_value(new(object)) end |