<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; }
#msg ul, pre { overflow: auto; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<title>[694] trunk/bucephala: </title>
</head>
<body>

<div id="msg">
<dl>
<dt>Revision</dt> <dd>694</dd>
<dt>Author</dt> <dd>method</dd>
<dt>Date</dt> <dd>2007-04-03 01:35:08 -0400 (Tue, 03 Apr 2007)</dd>
</dl>

<h3>Log Message</h3>
<pre></pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkbucephalabucephaladb">trunk/bucephala/bucephala.db</a></li>
<li><a href="#trunkbucephalabucephalarb">trunk/bucephala/bucephala.rb</a></li>
<li><a href="#trunkbucephalatestrb">trunk/bucephala/test.rb</a></li>
<li><a href="#trunkbucephalatypesalexandria_typesrb">trunk/bucephala/types/alexandria_types.rb</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkbucephalabucephaladb"></a>
<div class="binary"><h4>Modified: trunk/bucephala/bucephala.db</h4>
<pre class="diff"><span>
<span class="cx">(Binary files differ)
</span></span></pre></div>
<a id="trunkbucephalabucephalarb"></a>
<div class="modfile"><h4>Modified: trunk/bucephala/bucephala.rb (693 => 694)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bucephala/bucephala.rb        2007-04-03 04:16:55 UTC (rev 693)
+++ trunk/bucephala/bucephala.rb        2007-04-03 05:35:08 UTC (rev 694)
</span><span class="lines">@@ -6,50 +6,62 @@
</span><span class="cx">   $LOG = true
</span><span class="cx"> end
</span><span class="cx"> 
</span><ins>+# Bucephala is primarily intended to be called through DBus. 
+
</ins><span class="cx"> class BucephalaService
</span><span class="cx">  
</span><span class="cx">   def initialize(params)
</span><span class="cx">     load_types
</span><span class="cx">     og_connect(params)
</span><span class="cx">   end
</span><del>-  
-  def load_types
-    require 'types/buc_types'
-    puts &quot;require 'types/buc_types'...&quot; if $LOG
-    Dir[&quot;types/*&quot;].each do |file|
-      ext = File.extname(file)
-      base = File.basename(file, &quot;.*&quot;)
-      loadname = &quot;types/&quot; + base
-      unless base == &quot;buc_types&quot;
-        if ext == &quot;.rb&quot;
-          puts &quot;#{file}: #{base}, #{ext}&quot; if $LOG
-          require loadname if ext == &quot;.rb&quot;
-          puts &quot;require '#{loadname}'...&quot; if $LOG
-        end
-      end 
-    end
-  end
-  
</del><ins>+    
+  # Get back the bus  
</ins><span class="cx">   def get_dbus
</span><span class="cx">     PRDBus.system_bus
</span><span class="cx">   end
</span><span class="cx">   
</span><ins>+  # Supposed to retrieve every'thing', e.g., all descendants of Thing, but 
+  # doesn't yet.
</ins><span class="cx">   def get_things
</span><span class="cx">     Thing.all
</span><span class="cx">   end
</span><span class="cx">   
</span><ins>+  # Get back all libraries
</ins><span class="cx">   def get_libraries
</span><span class="cx">     Library.all
</span><span class="cx">   end
</span><span class="cx">   
</span><ins>+  # Get back all books
</ins><span class="cx">   def get_books
</span><span class="cx">     Book.all
</span><span class="cx">   end
</span><span class="cx">   
</span><ins>+  # Get back all authors
+  def get_authors
+    Author.all
+  end
+  
</ins><span class="cx">   #######
</span><span class="cx">   private
</span><span class="cx">   #######
</span><span class="cx">   
</span><ins>+  def load_types
+    require 'types/buc_types'
+    puts &quot;require 'types/buc_types'...&quot; if $LOG
+    Dir[&quot;types/*&quot;].each do |file|
+      ext = File.extname(file)
+      base = File.basename(file, &quot;.*&quot;)
+      loadname = &quot;types/&quot; + base
+      unless base == &quot;buc_types&quot;
+        if ext == &quot;.rb&quot;
+          puts &quot;#{file}: #{base}, #{ext}&quot; if $LOG
+          require loadname if ext == &quot;.rb&quot;
+          puts &quot;require '#{loadname}'...&quot; if $LOG
+        end
+      end 
+    end
+  end
+  
</ins><span class="cx">   def og_connect(params)
</span><span class="cx">     Og.setup( {:destroy =&gt; false,
</span><span class="cx">                :evolve_schema =&gt; :full, 
</span></span></pre></div>
<a id="trunkbucephalatestrb"></a>
<div class="modfile"><h4>Modified: trunk/bucephala/test.rb (693 => 694)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bucephala/test.rb        2007-04-03 04:16:55 UTC (rev 693)
+++ trunk/bucephala/test.rb        2007-04-03 05:35:08 UTC (rev 694)
</span><span class="lines">@@ -1,12 +1,10 @@
</span><span class="cx"> require 'test/unit'
</span><span class="cx"> require 'bucephala.rb'
</span><span class="cx"> 
</span><ins>+service = BucephalaService.new(:database =&gt; &quot;test_db.db&quot;)
+
</ins><span class="cx"> class TestBucephalaService &lt; Test::Unit::TestCase
</span><del>-  
-  def setup
-    @service = BucephalaService.new(:database =&gt; &quot;test_db.db&quot;)
-  end
-  
</del><ins>+    
</ins><span class="cx">   def test_add_library
</span><span class="cx">     library = Library.new(&quot;Test Library&quot;)
</span><span class="cx">     assert_equal library.name, &quot;Test Library&quot;
</span><span class="lines">@@ -14,9 +12,19 @@
</span><span class="cx">   
</span><span class="cx">   def test_add_book
</span><span class="cx">     book = Book.new(&quot;Of Mice and Men&quot;, &quot;John Steinbeck&quot;, &quot;A funny book about rabbits.&quot;)
</span><del>-    assert_equal book.name, &quot;Of Mice and Men&quot;
-    assert_equal book.author, &quot;John Steinbeck&quot;
-    assert_equal book.description, &quot;A funny book about rabbits.&quot;
</del><ins>+    assert_equal &quot;Of Mice and Men&quot;, book.name
+    assert_equal &quot;John Steinbeck&quot;, book.author.fullname
+    assert_equal &quot;A funny book about rabbits.&quot;, book.description
</ins><span class="cx">   end
</span><span class="cx">   
</span><ins>+  def test_add_author
+    author = Author.new(:name =&gt; &quot;John Steinbeck&quot;)
+    author2 = Author.new(:given_name =&gt; &quot;John&quot;, :nickname =&gt; &quot;Bob&quot;, :family_name =&gt; &quot;Steinbeck&quot;)
+    assert author.name == &quot;John Steinbeck&quot;
+    assert author.fullname == &quot;John Steinbeck&quot;
+    puts author2.fullname
+    assert author2.fullname == &quot;John 'Bob' Steinbeck&quot;
+    assert author2.fullname(false) == &quot;Steinbeck John&quot;    
+  end
+  
</ins><span class="cx"> end
</span></span></pre></div>
<a id="trunkbucephalatypesalexandria_typesrb"></a>
<div class="modfile"><h4>Modified: trunk/bucephala/types/alexandria_types.rb (693 => 694)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bucephala/types/alexandria_types.rb        2007-04-03 04:16:55 UTC (rev 693)
+++ trunk/bucephala/types/alexandria_types.rb        2007-04-03 05:35:08 UTC (rev 694)
</span><span class="lines">@@ -12,12 +12,59 @@
</span><span class="cx"> end
</span><span class="cx"> 
</span><span class="cx"> class Book &lt; Thing
</span><del>-  property :author, :description, String
</del><ins>+  property :description, String
</ins><span class="cx">   belongs_to :library, Library
</span><ins>+  has_many :authors, Author
</ins><span class="cx">   
</span><del>-  def initialize(name, author=&quot;&quot;, description=&quot;&quot;)
-    @name, @author, @description = name, author, description
</del><ins>+  def initialize(name, author_or_authors, description=&quot;&quot;)
+    @name, @description = name, description
+    unless author_or_authors.class == Array 
+      author = Author.new(:name =&gt; author_or_authors)
+      puts author.fullname
+      author.book = self
+      author.save!
+      puts authors
+      save!
+    else
+      puts &quot;Not implemented yet&quot;
+    end
</ins><span class="cx">   end  
</span><ins>+  
+  def author
+    authors
+  end
</ins><span class="cx"> 
</span><span class="cx"> end
</span><span class="cx"> 
</span><ins>+class Author &lt; Thing
+  property :given_name, :family_name, :middle_name, String
+  belongs_to :book, Book
+  
+  def initialize(params)
+    @given_name, @family_name, @middle_name, @nickname, @name = params[:given_name], 
+                                              params[:family_name],
+                                              params[:middle_name],
+                                              params[:nickname],
+                                              params[:name]
+    end  
+  
+  def fullname(western = true)
+    unless @given_name.nil? or @family_name.nil? 
+      if western
+        if @nickname
+          @given_name + &quot; '#{@nickname}' &quot; + @family_name
+        elsif @middle_name
+          @given_name + &quot; #{@middle_name} &quot; + @family_name
+        else
+          @given_name + &quot; &quot; + @family_name
+        end
+      else
+        @family_name + &quot; &quot; + @given_name
+      end
+    else
+      raise &quot;Need to give at least a name string for Author&quot; if @name.nil?
+      @name
+    end  
+  end
+
+end
</ins></span></pre>
</div>
</div>

</body>
</html>