# Mapping git repos to ruby objects und vice versa, need ideas

**URL:** <https://www.ruby-forum.com/t/mapping-git-repos-to-ruby-objects-und-vice-versa-need-ideas/174146>\
**Category:** Ruby\
**Created:** [August 21, 2009, 10:49am UTC](https://www.ruby-forum.com/t/mapping-git-repos-to-ruby-objects-und-vice-versa-need-ideas/174146 "2009-08-21T10:49:54Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Florian\_ASSSSmann](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/48db29/32.png) [@Florian\_ASSSSmann](https://www.ruby-forum.com/u/Florian_ASSSSmann)\
**Post date:** [August 21, 2009, 10:49am UTC](https://www.ruby-forum.com/t/mapping-git-repos-to-ruby-objects-und-vice-versa-need-ideas/174146/1 "2009-08-21T10:49:54Z")

</div>

Hi folks,

my last mail got a ambiguous subject so I try again with another one,  
since this  
isn’t a job offer… 🙂

I’m working on a lib called Chambermaid that creates snapshots of ruby  
objects and stores them in a git repository.

The main objective of Chambermaid is not to mess with your classes or  
objects. Instead Chambermaid should provide a simple but powerful API.

You work with browsers which will give you access to specific diaries  
(repos) and diaries which will give you access to specific pages  
(commits).  
These pages contain snapshots of your ruby object.

Still neither documentation nor write support is available. I’m  
currently  
struggling on how to snapshot files.

So here is my question:  
**Can you give me a hint how I should treat files and other more  
complex types?**

Resources: [http://github.com/boof/chambermaid](http://github.com/boof/chambermaid)

### ./example.rb

```
require 'chambermaid'
require 'person'

PeopleBrowser = Chambermaid.browser Person # => a Browser
foo_master_page = PeopleBrowser[1].last_page # => a Page
person_foo = foo_master_page.target # => a Person

# method missing binds a Context to the method called returning

```

the value  
# returned by method  
person\_foo.id == foo\_master\_page.id

### ./person.rb:

```
class Person
  attr_accessor :id, :firstname, :lastname, :email

  # tell Chambermaid where to find the repositories
  Chambermaid.keed_diary self,
      :in => File.join(File.dirname( __FILE__ ), 'people'),
      :as => :id
end

```

### ./people/init.rb

```
Chambermaid.ascribe Person do |has|
  # tell chambermaid where attributes should be read from and

```

write to

```
  # tell Chambermaid that the id is located in 'id.*' which reads
  # the value like:
  #
  # 1. a Context tries to find the correct filename => id.int.1
  # 2. the filename is divided based on '.' => id, int, '1'
  # 3. the last n-1 parts are filters that manipulate the value =>

```

int, ‘1’  
# 4. filters are applied in reverse order =\> ‘1’, int  
# 5. unrecognized filters, like ‘1’, return itself as value =\> ‘1’  
# 6. the int filter calls to\_i on ‘1’ =\> 1  
# 7. the result is assigned to the attribute id  
has.attribute :id, ‘int.%i’, :id

```
  # tell Chambermaid the meta.yml file contains the

```

attributes :firstname and  
# :lastname where .map adds the yml filter chain if not defined.  
has.map :meta do |meta|  
meta.reads(:firstname) { |meta| meta[‘firstname’] }  
meta.reads(:lastname) { |meta| meta[‘lastname’] }  
end

```
  has.attribute :email, 'uri'

end

```

### ./people/1/id.int.1

```
1

```

### ./people/1/meta.yml

```
---
firstname: Foo
lastname: Bar
...

```

### ./people/1/email.uri

```
mailto:removed_email_address@domain.invalid

```

Florian AÃŸmann

Fork Unstable Media | Hamburg  
[www.fork.de](http://www.fork.de) [http://www.fork.de/](http://www.fork.de/)
