public
Description: Pottery, same as Morph, plus ability to persist instances to a database; requires Morph and Soup gems.
Homepage: http://github.com/robmckinnon/pottery
Clone URL: git://github.com/robmckinnon/pottery.git
name age message
file .gitignore Thu Apr 10 06:40:55 -0700 2008 adding rest of pottery files [robmckinnon]
file CHANGELOG Loading commit data...
file LICENSE Thu Apr 10 06:40:55 -0700 2008 adding rest of pottery files [robmckinnon]
file Manifest Thu Apr 10 06:40:55 -0700 2008 adding rest of pottery files [robmckinnon]
file README
file Rakefile
directory lib/
directory spec/
README
Pottery allows you to emerge class definitions via calling assignment methods and
persist instances to a database; requires Morph and Soup gems.

[Note API subject to change]

== Pottery example

Here's example code showing Pottery playing with Hpricot:

> sqlite3 soup.db

> irb

 require 'rubygems'
 require 'pottery'; require 'hpricot'; require 'open-uri'

 class Hubbit
   include Pottery

   def initialize name=nil
     if name
       doc = Hpricot open("http://github.com/#{name}")

       (doc/'label').collect do |node|
         label = node.inner_text
         value = node.next_sibling.inner_text.strip

         morph(label, value)
       end
       morph(:id_name, name)
     end
   end
 end


The model emerges from the data. Let's start by looking up 'why':

 why = Hubbit.new 'why'

What new methods do we have?

 Hubbit.morph_methods # => ["email", "email=", "followers", "followers=",
    "id_name", "id_name=", "member_since", "member_since=", "name", "name=",
    "public_repos", "public_repos="]

Ah-ha, so we have a name attribute now:

 why.name #=> "why the lucky stiff"


Let's save why for later

 why.save


Ok, now it's later, let's restore why from the database

 why = Hubbit.restore('why') #=> <Hubbit @id_name="why", @name="why the lucky stiff" ...>



See LICENSE for the terms of this software.