remiprev/her — pull request #95 by remiprev (2013-04-15 18:38:15+00:00)
Title: Associations Refactor

_This has already been suggested in #85 and #93._

This pull request moves all the data fetching logic of associations into separate objects, `HasManyAssociation`, `HasOneAssociation` and `BelongsToAssociation`. This makes calling the association name method on a object return an association object, not the data.

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

class Comments
include Her::Model
end

user = User.find(1) # GET /users/1

# This is where the fun begins
comments = user.comments # => No data is fetched yet
user.comments.inspect # Fetch the data in user.attributes[:comments] or via an HTTP request

# Since the `user.comments` returns an association object (which is
# cached in an instance variable), it’s no longer possible to pass
# arguments to the method. Instead, we have the `#where` method:
comments = user.comments.where(approved: true) # Fetch the data via an HTTP request (GET /users/1/comments?approved=true)
```

How cool is that? :smile:

So, I just wanted to get feedback from you guys on this. This is not 100% done though, I still want to refactor the entire `spec/model/associations_spec.rb` file, because it’s currently very hard to maintain.