<!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 "require 'types/buc_types'..." if $LOG
- Dir["types/*"].each do |file|
- ext = File.extname(file)
- base = File.basename(file, ".*")
- loadname = "types/" + base
- unless base == "buc_types"
- if ext == ".rb"
- puts "#{file}: #{base}, #{ext}" if $LOG
- require loadname if ext == ".rb"
- puts "require '#{loadname}'..." 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 "require 'types/buc_types'..." if $LOG
+ Dir["types/*"].each do |file|
+ ext = File.extname(file)
+ base = File.basename(file, ".*")
+ loadname = "types/" + base
+ unless base == "buc_types"
+ if ext == ".rb"
+ puts "#{file}: #{base}, #{ext}" if $LOG
+ require loadname if ext == ".rb"
+ puts "require '#{loadname}'..." if $LOG
+ end
+ end
+ end
+ end
+
</ins><span class="cx"> def og_connect(params)
</span><span class="cx"> Og.setup( {:destroy => false,
</span><span class="cx"> :evolve_schema => :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 => "test_db.db")
+
</ins><span class="cx"> class TestBucephalaService < Test::Unit::TestCase
</span><del>-
- def setup
- @service = BucephalaService.new(:database => "test_db.db")
- end
-
</del><ins>+
</ins><span class="cx"> def test_add_library
</span><span class="cx"> library = Library.new("Test Library")
</span><span class="cx"> assert_equal library.name, "Test Library"
</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("Of Mice and Men", "John Steinbeck", "A funny book about rabbits.")
</span><del>- assert_equal book.name, "Of Mice and Men"
- assert_equal book.author, "John Steinbeck"
- assert_equal book.description, "A funny book about rabbits."
</del><ins>+ assert_equal "Of Mice and Men", book.name
+ assert_equal "John Steinbeck", book.author.fullname
+ assert_equal "A funny book about rabbits.", book.description
</ins><span class="cx"> end
</span><span class="cx">
</span><ins>+ def test_add_author
+ author = Author.new(:name => "John Steinbeck")
+ author2 = Author.new(:given_name => "John", :nickname => "Bob", :family_name => "Steinbeck")
+ assert author.name == "John Steinbeck"
+ assert author.fullname == "John Steinbeck"
+ puts author2.fullname
+ assert author2.fullname == "John 'Bob' Steinbeck"
+ assert author2.fullname(false) == "Steinbeck John"
+ 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 < 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="", description="")
- @name, @author, @description = name, author, description
</del><ins>+ def initialize(name, author_or_authors, description="")
+ @name, @description = name, description
+ unless author_or_authors.class == Array
+ author = Author.new(:name => author_or_authors)
+ puts author.fullname
+ author.book = self
+ author.save!
+ puts authors
+ save!
+ else
+ puts "Not implemented yet"
+ 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 < 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 + " '#{@nickname}' " + @family_name
+ elsif @middle_name
+ @given_name + " #{@middle_name} " + @family_name
+ else
+ @given_name + " " + @family_name
+ end
+ else
+ @family_name + " " + @given_name
+ end
+ else
+ raise "Need to give at least a name string for Author" if @name.nil?
+ @name
+ end
+ end
+
+end
</ins></span></pre>
</div>
</div>
</body>
</html>