mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-23 06:16:50 +00:00
25 lines
415 B
Ruby
25 lines
415 B
Ruby
class Model
|
|
include ActiveModel::SerializerSupport
|
|
|
|
def initialize(hash={})
|
|
@attributes = hash
|
|
end
|
|
|
|
def read_attribute_for_serialization(name)
|
|
@attributes[name]
|
|
end
|
|
end
|
|
|
|
class ModelSerializer < ActiveModel::Serializer
|
|
attributes :attr1, :attr2
|
|
|
|
def attr2
|
|
attr2 = object.read_attribute_for_serialization(:attr2)
|
|
if scope
|
|
attr2 + '-' + scope
|
|
else
|
|
attr2
|
|
end
|
|
end
|
|
end
|