Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add documentation for hooks

  • Loading branch information...
commit 3bb82327675ec035d00a3a36504e98aba601c65f 1 parent bd37130
@remiprev authored
Showing with 18 additions and 1 deletion.
  1. +17 −0 README.md
  2. +1 −1  lib/her/version.rb
View
17 README.md
@@ -166,6 +166,23 @@ For `belongs_to` relationship, an extra HTTP request (to `GET /organizations/2`)
However, subsequent calls to `#comments` or `#role` will not trigger the extra HTTP request.
+## Hooks
+
+You can add *before* and *after* hooks to your models that are triggered on specific actions (`save`, `update`, `create`, `destroy`):
+
+```ruby
+class User
+ include Her::Model
+ before_save :set_internal_id
+
+ def set_internal_id
+ self.internal_id = 42 # Will be passed in the HTTP request
+ end
+end
+```
+
+In the future, adding hooks to all models will be possible, as well as defining and triggering your own hooks (eg. for your custom requests).
+
## Custom requests
You can easily add custom methods for your models. You can either use `get_collection` (which maps the returned data to a collection of resources), `get_resource` (which maps the returned data to a single resource) or `get_raw` (which yields the parsed data return from the HTTP request). Other HTTP methods are supported (`post_raw`, `put_resource`, etc.)
View
2  lib/her/version.rb
@@ -1,3 +1,3 @@
module Her
- VERSION = "0.1.5"
+ VERSION = "0.1.6"
end
Please sign in to comment.
Something went wrong with that request. Please try again.