ActiveModel Serializer:将属性作为方法访问

ActiveModel Serializer: access attributes as methods

如何将序列化程序中定义的属性作为方法访问?

class Test < ActiveModel::Serializer 
  attributes :a, :b, :c
end

s = Test.new(Object)
s.a

我需要这个来授权,它曾经在 0.8 版本中可用/

序列化器上不再定义属性方法,必须通过对象显式访问

class MySerializer
  attributes :foo, :bar

  def foo
    bar + 1 # bar does not work, needs to be object.bar in 0.10
  end
end

https://github.com/rails-api/active_model_serializers/blob/v0.10.6/docs/howto/upgrade_from_0_8_to_0_10.md#010-breaking-changes