josevalim/active_model_serializers — pull request #80 by twinturbo (2012-06-15 12:34:48+00:00)
Title: Private attributes

My app has a lot of user specific information. This information should only be included if the serialized object is the serialization scope. This PR adds a little sugar around it. This makes way is easier than overriding `attributes` and doing conditionals IMO.

New API:

```ruby
class UserSerializer < ActiveModel::Serializer
has_many :preferences, :private => true
attribute :api_key, :private => true
private_attributes :email, :foo, :bar
```

Previous solutions

```ruby
def attributes
if options[:scope] == object
super.merge(:email => object.email) # etc
else
super
end
end
```