{"action":"created","issue":{"url":"https://api.github.com/repos/rails-api/active_model_serializers/issues/1356","labels_url":"https://api.github.com/repos/rails-api/active_model_serializers/issues/1356/labels{/name}","comments_url":"https://api.github.com/repos/rails-api/active_model_serializers/issues/1356/comments","events_url":"https://api.github.com/repos/rails-api/active_model_serializers/issues/1356/events","html_url":"https://github.com/rails-api/active_model_serializers/pull/1356","id":119609120,"number":1356,"title":"Add inline syntax for attributes and associations","user":{"login":"bf4","id":142914,"avatar_url":"https://avatars.githubusercontent.com/u/142914?v=3","gravatar_id":"","url":"https://api.github.com/users/bf4","html_url":"https://github.com/bf4","followers_url":"https://api.github.com/users/bf4/followers","following_url":"https://api.github.com/users/bf4/following{/other_user}","gists_url":"https://api.github.com/users/bf4/gists{/gist_id}","starred_url":"https://api.github.com/users/bf4/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bf4/subscriptions","organizations_url":"https://api.github.com/users/bf4/orgs","repos_url":"https://api.github.com/users/bf4/repos","events_url":"https://api.github.com/users/bf4/events{/privacy}","received_events_url":"https://api.github.com/users/bf4/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/rails-api/active_model_serializers/labels/Changelog%20Missing","name":"Changelog Missing","color":"fbca04"},{"url":"https://api.github.com/repos/rails-api/active_model_serializers/labels/Feature","name":"Feature","color":"009800"},{"url":"https://api.github.com/repos/rails-api/active_model_serializers/labels/Needs%20Code%20Review","name":"Needs Code Review","color":"fbca04"},{"url":"https://api.github.com/repos/rails-api/active_model_serializers/labels/Needs%20Team%20Discussion","name":"Needs Team Discussion","color":"5319e7"},{"url":"https://api.github.com/repos/rails-api/active_model_serializers/labels/Ready%20for%20PR","name":"Ready for PR","color":"009800"},{"url":"https://api.github.com/repos/rails-api/active_model_serializers/labels/V:%200.10.x","name":"V: 0.10.x","color":"bfd4f2"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":7,"created_at":"2015-11-30T23:52:53Z","updated_at":"2015-12-02T06:28:33Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/rails-api/active_model_serializers/pulls/1356","html_url":"https://github.com/rails-api/active_model_serializers/pull/1356","diff_url":"https://github.com/rails-api/active_model_serializers/pull/1356.diff","patch_url":"https://github.com/rails-api/active_model_serializers/pull/1356.patch"},"body":"Goals:\r\n\r\n1. Allow defining attributes so that they don't conflict with existing methods\r\n1. Allow customizing associations e.g. comments.last(5)\r\n1. Move toward removing dynamically defined methods on the serializer\r\n\r\nBased on work in #1262, #1354\r\n\r\nRef: #1263, #1261, #1311\r\n\r\nThis PR is intended as a starting point for further work improving how\r\nserializers map their resources attributes and associations\r\n\r\nIntroduced, in support of this:\r\n\r\n- Serializer#serialized_attributes\r\n- Serializer#serialized_associations\r\n\r\n(currently includes #1355 which I needed locally)\r\n\r\nI expect to need to make a few changes and rebase"},"comment":{"url":"https://api.github.com/repos/rails-api/active_model_serializers/issues/comments/161193512","html_url":"https://github.com/rails-api/active_model_serializers/pull/1356#issuecomment-161193512","issue_url":"https://api.github.com/repos/rails-api/active_model_serializers/issues/1356","id":161193512,"user":{"login":"bf4","id":142914,"avatar_url":"https://avatars.githubusercontent.com/u/142914?v=3","gravatar_id":"","url":"https://api.github.com/users/bf4","html_url":"https://github.com/bf4","followers_url":"https://api.github.com/users/bf4/followers","following_url":"https://api.github.com/users/bf4/following{/other_user}","gists_url":"https://api.github.com/users/bf4/gists{/gist_id}","starred_url":"https://api.github.com/users/bf4/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bf4/subscriptions","organizations_url":"https://api.github.com/users/bf4/orgs","repos_url":"https://api.github.com/users/bf4/repos","events_url":"https://api.github.com/users/bf4/events{/privacy}","received_events_url":"https://api.github.com/users/bf4/received_events","type":"User","site_admin":false},"created_at":"2015-12-02T06:28:33Z","updated_at":"2015-12-02T06:28:33Z","body":"\r\n@noahsilas I added your commit from that branch and made one major and a few minor changes\r\n\r\n1. removed dynamically define methods (yay!)\r\n  - added the `_fragment` attributes to the mapping. This handles the `_fragmented.respond_to?(attr)` the prevented the dynamic method from being defined\r\n  - added `Serializer#read_attribute_for_serialization` (part of the ActiveModel::Serialization API) to handle first getting the attribute from a serializer method, then from the object.\r\n    - Checking if the attribute is defined on the serializer handles the dynamic method check for `method_defined?(attr)`, except now it just checks if there's a public instance method by that name not defined in Object\r\n  - **possible regression**: removed referring to object attributes in the serializer without calling them directly on object.  (I didn't even know this was possible. We could add a respond_to_missing / method_missing for this)\r\n  - \r\n1. changed `_attributes_map` to `_attribute_mappings` so that the collection element could be referred to as each of an `_attribute_mapping`.\r\n  - Changed the mapping from a hash to an object\r\n  ```diff\r\n  -      _attributes_map[key] = { attr: attr, reader: reader }\r\n  +      _attribute_mappings[key] = Attribute.new(attr, reader)\r\n  ```\r\n  - Defined the object as a callable that knows the attribute `name` it represents\r\n  ```diff\r\n  +    Attribute = Struct.new(:name, :reader) do\r\n  +      delegate :call, to: :reader\r\n  +    end\r\n  ```"}}