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.