dam5s/happymapper — pull request #16 by zrob (2012-09-25 21:23:08+00:00)
Title: Reusable base class

Can create reusable base classes. Below sandwich and burger are basically the same, so use a base class for them in a larger doc. The key is the tags. The base item has a tag of '*'. The parent doc chooses the tag to use when parsing and when printing to xml.

```xml

```

```ruby
class StackedFoodItem
include HappyMapper
tag '*'
attribute :container, String
attribute :filler, String
end

class Lunch
include HappyMapper
tag 'lunch'
has_one :burger, StackedFoodItem, :tag => 'burger'
has_many :sandwiches, StackedFoodItem, :tag => 'sandwich'
end

lunch = Lunch.parse(xml)
lunch.burger.filler += ' and mustard'
lunch.sandwiches[0].filler += ' and ham'
```