Class: GroupSerializer
- Inherits:
-
Object
- Object
- GroupSerializer
- Defined in:
- lib/serializer/group_serializer.rb
Instance Method Summary collapse
-
#initialize(objects, serializer: nil) ⇒ GroupSerializer
constructor
A new instance of GroupSerializer.
- #to_json ⇒ Object
Constructor Details
#initialize(objects, serializer: nil) ⇒ GroupSerializer
Returns a new instance of GroupSerializer.
2 3 4 5 6 7 |
# File 'lib/serializer/group_serializer.rb', line 2 def initialize(objects, serializer: nil) raise ArgumentError, 'serializer needs to be specified' if serializer.nil? @objects = objects @serializer = serializer end |
Instance Method Details
#to_json ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/serializer/group_serializer.rb', line 9 def to_json(*) Appsignal.instrument( 'json.serialize', 'Group serializer', @serializer.to_s ) do result = @objects.map { |object| @serializer.new(object).to_h } Oj.dump(result, mode: :json) end end |