--Apple-Mail-2-228640982
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain;
charset=UTF-8;
delsp=yes;
format=flowed
Hmmmm. Having to inherit *after* the open_database
just Feels Wrong somehow. Would it work the same if you
just did the open_database before any db operations?
In fact, I'm not sure I'd do inheritance at all. I'd have
to think about it.
Why do Book and Author have to have an is-a relationship
with KirbyRecord::Base? So you can do Author.find() and
so on?
BTW, I think to_sym is preferred over intern lately.
OK, I'm catching on to the reason for the inheritance. Is there
any reason a module wouldn't suffice? I'm not sure it matters
either way, but I tend to include modules more than I actually
inherit.
So far I like the general idea.
Ok I'm including a patch that lets you connect after the inherit.
eg.
class Author < KirbyRecord::Base
end
KirbyRecord::Base.open_database( )
authors =3D Author.find
all)
author =3D Author.new # will also cause the reflection and =20
modifications to the Author class to occurr
This patch also incidently removes the reliance on the inherited =20
hook, so it would be enitrely possible to make this a module. I'm =20
still mulling that over, and I want to hear some more thoughts on the =20=
subject before I decide.
=EF=BF=BC=
--Apple-Mail-2-228640982
Content-Type: multipart/mixed;
boundary=Apple-Mail-3-228640982
--Apple-Mail-3-228640982
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html;
charset=ISO-8859-1
<HTML><BODY style=3D"word-wrap: break-word; -khtml-nbsp-mode: space; =
-khtml-line-break: after-white-space; "><BR><DIV><DIV>On Sep 14, 2005, =
at 1:50 AM, Hal Fulton wrote:</DIV><BR =
class=3D"Apple-interchange-newline"><BLOCKQUOTE type=3D"cite"><P =
style=3D"margin: 0.0px 0.0px 0.0px 0.0px"><FONT face=3D"Helvetica" =
size=3D"3" style=3D"font: 12.0px Helvetica">Hmmmm. Having to inherit =
*after* the open_database</FONT></P> <P style=3D"margin: 0.0px 0.0px =
0.0px 0.0px"><FONT face=3D"Helvetica" size=3D"3" style=3D"font: 12.0px =
Helvetica">just Feels Wrong somehow. Would it work the same if =
you</FONT></P> <P style=3D"margin: 0.0px 0.0px 0.0px 0.0px"><FONT =
face=3D"Helvetica" size=3D"3" style=3D"font: 12.0px Helvetica">just did =
the open_database before any db operations?</FONT></P> <P style=3D"margin:=
0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: =
14.0px"><BR></P> <P style=3D"margin: 0.0px 0.0px 0.0px 0.0px"><FONT =
face=3D"Helvetica" size=3D"3" style=3D"font: 12.0px Helvetica">In fact, =
I'm not sure I'd do inheritance at all. I'd have</FONT></P> <P =
style=3D"margin: 0.0px 0.0px 0.0px 0.0px"><FONT face=3D"Helvetica" =
size=3D"3" style=3D"font: 12.0px Helvetica">to think about =
it.</FONT></P> <P style=3D"margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px =
Helvetica; min-height: 14.0px"><BR></P> <P style=3D"margin: 0.0px 0.0px =
0.0px 0.0px"><FONT face=3D"Helvetica" size=3D"3" style=3D"font: 12.0px =
Helvetica">Why do Book and Author have to have an is-a =
relationship</FONT></P> <P style=3D"margin: 0.0px 0.0px 0.0px =
0.0px"><FONT face=3D"Helvetica" size=3D"3" style=3D"font: 12.0px =
Helvetica">with KirbyRecord::Base? So you can do Author.find() =
and</FONT></P> <P style=3D"margin: 0.0px 0.0px 0.0px 0.0px"><FONT =
face=3D"Helvetica" size=3D"3" style=3D"font: 12.0px Helvetica">so =
on?</FONT></P> <P style=3D"margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px =
Helvetica; min-height: 14.0px"><BR></P> <P style=3D"margin: 0.0px 0.0px =
0.0px 0.0px"><FONT face=3D"Helvetica" size=3D"3" style=3D"font: 12.0px =
Helvetica">BTW, I think to_sym is preferred over intern =
lately.</FONT></P> <P style=3D"margin: 0.0px 0.0px 0.0px 0.0px; font: =
12.0px Helvetica; min-height: 14.0px"><BR></P> <BR><BLOCKQUOTE =
type=3D"cite"><P style=3D"margin: 0.0px 0.0px 0.0px 10.0px"><FONT =
face=3D"Helvetica" size=3D"3" style=3D"font: 12.0px Helvetica">class =
Person < KirbyRecord::Base</FONT></P> <P style=3D"margin: 0.0px 0.0px =
0.0px 10.0px"><FONT face=3D"Helvetica" size=3D"3" style=3D"font: 12.0px =
Helvetica">end</FONT></P> <P style=3D"margin: 0.0px 0.0px 0.0px =
10.0px"><FONT face=3D"Helvetica" size=3D"3" style=3D"font: 12.0px =
Helvetica">person1 =3D Person.new</FONT></P> <P style=3D"margin: 0.0px =
0.0px 0.0px 10.0px"><FONT face=3D"Helvetica" size=3D"3" style=3D"font: =
12.0px Helvetica">person1.set_name "John Doe"</FONT></P> <P =
style=3D"margin: 0.0px 0.0px 0.0px 10.0px"><FONT face=3D"Helvetica" =
size=3D"3" style=3D"font: 12.0px Helvetica">person1.set_age =
25</FONT></P> <P style=3D"margin: 0.0px 0.0px 0.0px 10.0px"><FONT =
face=3D"Helvetica" size=3D"3" style=3D"font: 12.0px =
Helvetica">person1.save</FONT></P> <BR></BLOCKQUOTE><P style=3D"margin: =
0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: =
14.0px"><BR></P> <P style=3D"margin: 0.0px 0.0px 0.0px 0.0px"><FONT =
face=3D"Helvetica" size=3D"3" style=3D"font: 12.0px Helvetica">OK, I'm =
catching on to the reason for the inheritance. Is there</FONT></P> <P =
style=3D"margin: 0.0px 0.0px 0.0px 0.0px"><FONT face=3D"Helvetica" =
size=3D"3" style=3D"font: 12.0px Helvetica">any reason a module wouldn't =
suffice? I'm not sure it matters</FONT></P> <P style=3D"margin: 0.0px =
0.0px 0.0px 0.0px"><FONT face=3D"Helvetica" size=3D"3" style=3D"font: =
12.0px Helvetica">either way, but I tend to include modules more than I =
actually</FONT></P> <P style=3D"margin: 0.0px 0.0px 0.0px 0.0px"><FONT =
face=3D"Helvetica" size=3D"3" style=3D"font: 12.0px =
Helvetica">inherit.</FONT></P> <P style=3D"margin: 0.0px 0.0px 0.0px =
0.0px; font: 12.0px Helvetica; min-height: 14.0px"><BR></P> <P =
style=3D"margin: 0.0px 0.0px 0.0px 0.0px"><FONT face=3D"Helvetica" =
size=3D"3" style=3D"font: 12.0px Helvetica">So far I like the general =
idea.</FONT></P> <BR =
class=3D"Apple-interchange-newline"></BLOCKQUOTE></DIV><BR><DIV>Ok I'm =
including a patch that lets you connect after the inherit.</DIV><DIV><BR =
class=3D"khtml-block-placeholder"></DIV><DIV>eg.</DIV><DIV><BR =
class=3D"khtml-block-placeholder"></DIV><DIV>class Author < =
KirbyRecord::Base</DIV><DIV>end</DIV><DIV><BR =
class=3D"khtml-block-placeholder"></DIV><DIV>KirbyRecord::Base.open_databa=
se( )</DIV><DIV><BR class=3D"khtml-block-placeholder"></DIV><DIV>authors =
=3D Author.find
all)</DIV><DIV><BR =
class=3D"khtml-block-placeholder"></DIV><DIV>author =3D Author.new # =
will also cause the reflection and modifications to the Author class to =
occurr</DIV><DIV><BR class=3D"khtml-block-placeholder"></DIV><DIV><BR =
class=3D"khtml-block-placeholder"></DIV><DIV>=A0This patch also =
incidently removes the reliance on the inherited hook, so it would be =
enitrely possible to make this a module. I'm still mulling that over, =
and I want to hear some more thoughts on the subject before I =
decide.</DIV><DIV><BR =
class=3D"khtml-block-placeholder"></DIV><DIV><SPAN></SPAN></DIV></BODY></H=
TML>=
--Apple-Mail-3-228640982
Content-Transfer-Encoding: 7bit
Content-Type: application/octet-stream;
x-unix-mode=0644;
name="kirbyrecord.smartinform.patch"
Content-Disposition: attachment;
filename=kirbyrecord.smartinform.patch
--- kirbyrecord.rb.0 2005-09-13 22:25:40.000000000 -0400
+++ kirbyrecord.rb 2005-09-14 11:27:01.000000000 -0400
@@ -11,47 +11,49 @@
end
def initialize
+ self.class.inform_about_table
@state = {}
end
- def self.inherited(subclass)
- subclass.inform_about_table
- subclass.class_eval do
- subclass.fields.each do |name, type|
- define_method("get_#{name}".intern) do
- @state[name]
- end
-
- define_method("set_#{name}".intern) do |value|
- @state[name] = case type
- when :String
- value.to_s
- when :Integer
- value.to_i
- when :Float
- value.to_f
- when :Boolean
- if value then true else false end
- when
ate
- value
- when
ateTime
- value
- end
- end
- end
- end
- end
- def self.inform_about_table
+ def self.inform_about_table(force = false)
+ unless force
+ return self if @fields
+ end
table = get_database.get_table(table_name)
@fields = {}
table.field_names.zip( table.field_types ) do |field_name, field_type|
@fields[field_name] = field_type
end
+ class_eval do
+ fields.each do |name, type|
+ define_method("get_#{name}".intern) do
+ @state[name]
+ end
+
+ define_method("set_#{name}".intern) do |value|
+ @state[name] = case type
+ when :String
+ value.to_s
+ when :Integer
+ value.to_i
+ when :Float
+ value.to_f
+ when :Boolean
+ if value then true else false end
+ when
ate
+ value
+ when
ateTime
+ value
+ end
+ end
+ end
+ end
self
end
def self.find(card)
+ inform_about_table
db = get_database
tbl = db.get_table(table_name)
results = if block_given? then tbl.select { |r| yield(r) } else tbl.select end
--Apple-Mail-3-228640982
Content-Transfer-Encoding: 7bit
Content-Type: text/html;
charset=US-ASCII
<HTML><BODY style="word-wrap: break-word; -khtml-nbsp-mode: space; -khtml-line-break: after-white-space; "><DIV><SPAN></SPAN></DIV></BODY></HTML>
--Apple-Mail-3-228640982--
--Apple-Mail-2-228640982--