README.md in representable-1.5.3 vs README.md in representable-1.6.0

- old
+ new

@@ -172,10 +172,29 @@ from_json(%{{"name":"Offspring","songs":[{"title":"Genocide"},{"title":"Nitro","composers":["Offspring"]}]}}) #=> #<Album name="Offspring", songs=[#<Song title="Genocide">, #<Song title="Nitro", composers=["Offspring"]>]> ``` +## Inline Representers + +If you don't want to maintain two separate modules when nesting representations you can define the `SongRepresenter` inline. + +```ruby +module AlbumRepresenter + include Representable::JSON + + property :name + + collection :songs, class: Song do + property :title + property :track + collection :composers + end +``` + +This works both for representer modules and decorators. + ## Decorator vs. Extend People who dislike `:extend` go use the `Decorator` strategy! ```ruby @@ -574,11 +593,11 @@ property :name end ``` -I do not recommend this approach as it bloats your domain classes with representation logic that is barely needed elsewhere. +I do not recommend this approach as it bloats your domain classes with representation logic that is barely needed elsewhere. Use [decorators](#decorator-vs-extend) instead. ## More Options Here's a quick overview about other available options for `#property` and its bro `#collection`. @@ -677,19 +696,21 @@ property :title property :recorded_at, :type => DateTime, :default => "May 12th, 2012" end ``` -When using a decorator representer, use the `Representable::Decorator::Coercion` module. +In a decorator it works alike. ```ruby module SongRepresenter < Representable::Decorator include Representable::JSON - include Representable::Decorator::Coercion + include Representable::Coercion property :recorded_at, :type => DateTime end ``` + +Coercing values only happens when rendering or parsing a document. Representable does not create accessors in your model as `virtus` does. ## Undocumented Features (Please don't read this section!)