README.md in representable-1.5.0 vs README.md in representable-1.5.1
- old
+ new
@@ -62,11 +62,11 @@
#=> #<Song title="Roxanne", track=nil>
```
## Extend vs. Decorator
-If you don't want representer modules to be mixed into your objects (using `#extend`) you can use the `Decorator` strategy [described below](https://github.com/apotonick/representable#decorator-vs-extend). Decorating instead of extending was introduced in 1.4.
+If you don't want representer modules to be mixed into your objects (using `#extend`) you can use the `Decorator` strategy [described below](#decorator-vs-extend). Decorating instead of extending was introduced in 1.4.
## Aliasing
If your property name doesn't match the name in the document, use the `:as` option.
@@ -202,9 +202,32 @@
include Representable::JSON
collection :songs, :class => Song, :decorator => SongRepresentation
end
```
+
+### Helpers In Decorators
+
+In module representers you can add methods for properties.
+
+```ruby
+module SongRepresenter
+ property :title
+
+ def title
+ @name
+ end
+```
+
+That works as the method is mixed into the represented object. Of course, this doesn't work with decorators.
+
+Use `:getter` or `:setter` to dynamically add a method for the represented object.
+
+```ruby
+class SongRepresenter < Representable::Decorator
+ property :title, getter: lambda { |*| @name }
+```
+As always, the block is executed in the represented object's context.
## XML Support
While representable does a great job with JSON, it also features support for XML, YAML and pure ruby hashes.