remiprev/her — pull request #103 by remiprev (2013-04-19 12:12:29+00:00)
Title: Lazy-loaded collections and associations

This pull request refactors two things: Associations and relations.

### Associations

Association name methods are now cached and the fetched data is lazy-loaded. Which means we can no longer pass arguments to the association name method.

```ruby
class User
include Her::Model
has_many :comments
end

# This is no longer possible
comments = User.find(1).comments(:approved => 1)

# We have to use this
comments = User.find(1).comments.where(:approved => 1)

comments = User.find(1).comments # The data is not fetched yet!
puts comments.inspect # Now it is!
```

### Relations

Like associations, we can now use chainable `where` calls to build our query before fetching the data. This works with both `all` and `create`.

```ruby
class User
include Her::Model
end

admins = User.where(:admin => 1)

# POST /users with `admin=1&name=Rémi+Prévost`
new_admin = admins.create(:name => "Rémi Prévost")

# GET /users?admin=1&foo=bar
all_admins = admins.all(:foo => "bar") # The data is not fetched yet!
puts all_admins.inspect # Now it is!
```

This is something I’m hoping to launch for the 0.6 version, as it might break a few things (especially the arguments for the association name methods).

What do you guys think?