datamapper/dm-core — Issue #173: "Greedy" meta-property that makes out-of-model properties accessible
Author: lgierth
Created: 2012-01-08 16:00:58+00:00
State: open

As an example for what I want I'll use the YAML adapter for working with configuration files.

Let's say I have a configuration file that's devided into different sections:

```yml
---
- name: section
key: value
foo: bar
- name: other_section
herp: derp
```

The key-value pairs in each section are supposed to be more or less fluid. Though currently I'd need to specify each key in the model in order for DataMapper to read/write it.

I have some code in dm-types ([greedy branch](https://github.com/lgierth/dm-types/tree/greedy)) and dm-yaml-adapter ([greedy branch](https://github.com/lgierth/dm-yaml-adapter/tree/greedy)) that implements a kind of meta-property that reads and writes all properties that are not part of the defined model and makes them accessible as a Hash.

With these changes I'm able to define the following model:

```ruby
class Config
include DataMapper::Resource
property :name, String, :key => true
property :payload, DataMapper::Property::Greedy
end
```

The greedy property needs support from each used adapter, as the adapter needs to read and write the out-of-model properties to the greedy property.

What do you think about this? Are there other approaches to this or even an existing solution?