Class: AbstractSerializer
- Inherits:
-
Object
- Object
- AbstractSerializer
show all
- Defined in:
- lib/c80_shared/abstract_serializer.rb
Class Method Summary
collapse
Class Method Details
.available_attributes ⇒ Object
19
20
21
|
# File 'lib/c80_shared/abstract_serializer.rb', line 19
def available_attributes
[]
end
|
.opts ⇒ Object
23
24
25
|
# File 'lib/c80_shared/abstract_serializer.rb', line 23
def opts
@opts
end
|
.serialize(model, attributes: available_attributes, opts: {}) ⇒ Object
8
9
10
11
12
13
14
15
16
17
|
# File 'lib/c80_shared/abstract_serializer.rb', line 8
def serialize(model, attributes: available_attributes, opts: {})
@opts = opts
unknown_attributes = attributes - available_attributes
if unknown_attributes.present?
raise StandardError, sprintf('Unknown attributes: %s', unknown_attributes.join(', '))
end
attributes.each_with_object({}) { |attribute, result| result.merge!(send(attribute, model)) }
end
|