libgit2/rugged — pull request #307 by arthurschreiber (2014-01-30 20:24:43+00:00)
Title: Introduce Collections

This change introduces Collections for References, Branches, and Tags, and splits `Rugged::Tag` into `Rugged::Tag`, a class that represents references in the `refs/tags` namespace, and `Rugged::Tag::Annotation`, which represents the tag objects in the ODB.

## Tags as Refs

See #255 for information on that.

## Collections

Methods that were previously defined on the classes `Rugged::Reference`, `Rugged::Branch` and `Rugged::Tag` were separated off into different collection classes, which all expose a very similar interface and streamline the Rugged API quite a bit:

```ruby
# Looking up and modifying references
ref = repo.references["refs/heads/master"]

# Creating a new branch
repo.references.create("refs/heads/branch", ref.target)

# Modifying branches
repo.references.delete(ref)
repo.references.update("refs/heads/branch", "bd062e5cc99ff9ea1dc924d032843718493aaa2d")

# Looking up a branch
branch = repo.branches["master"]

# Looking up a tag
tag = repo.tags["v1.0"]
```

As `Rugged::Tag` and `Rugged::Branch` both inherit from `Rugged::Reference` now, gives us some very interesting properties:

```
tag = repo.tags["v1.0"]
repo.references.delete(tag) # Works!

branch = repo.branches["master"]
repo.references.delete(branch) # Works!
```

Basically, any code that expects to work with References will automagically also work when passed a Branch or a Tag.