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