Skip to content
This repository has been archived by the owner on Apr 17, 2018. It is now read-only.

"Greedy" meta-property that makes out-of-model properties accessible #173

Open
ghost opened this issue Jan 8, 2012 · 1 comment
Open
Assignees

Comments

@ghost
Copy link

ghost commented Jan 8, 2012

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:

---
- 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) and dm-yaml-adapter (greedy branch) 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:

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?

@ghost
Copy link
Author

ghost commented Jan 21, 2012

This is very similar to what Rails 3.2 does with ActiveRecord::Base.store

@ghost ghost assigned myabc Jan 21, 2012
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant