lafcadio 0.4.3 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/lafcadio_schema +28 -0
- data/lib/lafcadio.rb +3 -4
- data/lib/lafcadio.rb~ +3 -4
- data/lib/lafcadio/TestSuite.rb +2 -0
- data/lib/lafcadio/TestSuite.rb~ +16 -0
- data/lib/lafcadio/dateTime.rb +93 -2
- data/lib/lafcadio/{dateTime/Month.rb → dateTime.rb~} +33 -33
- data/lib/lafcadio/depend.rb +3 -0
- data/lib/lafcadio/domain.rb +574 -70
- data/lib/lafcadio/domain.rb~ +570 -70
- data/lib/lafcadio/mock.rb +92 -2
- data/lib/lafcadio/mock.rb~ +93 -0
- data/lib/lafcadio/objectField.rb +614 -3
- data/lib/lafcadio/objectField.rb~ +618 -0
- data/lib/lafcadio/objectStore.rb +662 -19
- data/lib/lafcadio/objectStore.rb~ +746 -0
- data/lib/lafcadio/query.rb +415 -31
- data/lib/lafcadio/query.rb~ +572 -0
- data/lib/lafcadio/schema.rb +57 -2
- data/lib/lafcadio/test.rb +17 -2
- data/lib/lafcadio/{test/LafcadioTestCase.rb → test.rb~} +5 -5
- data/lib/lafcadio/test/testconfig.dat +1 -1
- data/lib/lafcadio/util.rb +337 -20
- metadata +16 -77
- data/lib/lafcadio/domain/DomainObject.rb +0 -375
- data/lib/lafcadio/domain/DomainObject.rb~ +0 -371
- data/lib/lafcadio/domain/MapObject.rb +0 -22
- data/lib/lafcadio/domain/ObjectType.rb +0 -80
- data/lib/lafcadio/includer.rb +0 -18
- data/lib/lafcadio/mock/MockDbBridge.rb +0 -78
- data/lib/lafcadio/mock/MockDbBridge.rb~ +0 -74
- data/lib/lafcadio/mock/MockObjectStore.rb +0 -20
- data/lib/lafcadio/objectField/AutoIncrementField.rb +0 -25
- data/lib/lafcadio/objectField/BooleanField.rb +0 -83
- data/lib/lafcadio/objectField/DateField.rb +0 -33
- data/lib/lafcadio/objectField/DateTimeField.rb +0 -25
- data/lib/lafcadio/objectField/DecimalField.rb +0 -41
- data/lib/lafcadio/objectField/EmailField.rb +0 -28
- data/lib/lafcadio/objectField/EnumField.rb +0 -62
- data/lib/lafcadio/objectField/FieldValueError.rb +0 -4
- data/lib/lafcadio/objectField/IntegerField.rb +0 -15
- data/lib/lafcadio/objectField/LinkField.rb +0 -92
- data/lib/lafcadio/objectField/LinkField.rb~ +0 -86
- data/lib/lafcadio/objectField/MoneyField.rb +0 -13
- data/lib/lafcadio/objectField/MonthField.rb +0 -16
- data/lib/lafcadio/objectField/ObjectField.rb +0 -142
- data/lib/lafcadio/objectField/PasswordField.rb +0 -29
- data/lib/lafcadio/objectField/StateField.rb +0 -13
- data/lib/lafcadio/objectField/SubsetLinkField.rb +0 -25
- data/lib/lafcadio/objectField/TextField.rb +0 -23
- data/lib/lafcadio/objectField/TextListField.rb +0 -21
- data/lib/lafcadio/objectField/TimeStampField.rb +0 -15
- data/lib/lafcadio/objectStore/Cache.rb +0 -81
- data/lib/lafcadio/objectStore/Committer.rb +0 -65
- data/lib/lafcadio/objectStore/CouldntMatchObjectTypeError.rb +0 -4
- data/lib/lafcadio/objectStore/DbBridge.rb +0 -140
- data/lib/lafcadio/objectStore/DbBridge.rb~ +0 -140
- data/lib/lafcadio/objectStore/DomainComparable.rb +0 -25
- data/lib/lafcadio/objectStore/DomainObjectInitError.rb +0 -9
- data/lib/lafcadio/objectStore/DomainObjectNotFoundError.rb +0 -4
- data/lib/lafcadio/objectStore/DomainObjectProxy.rb +0 -62
- data/lib/lafcadio/objectStore/DomainObjectSqlMaker.rb +0 -74
- data/lib/lafcadio/objectStore/ObjectStore.rb +0 -207
- data/lib/lafcadio/objectStore/ObjectStore.rb~ +0 -207
- data/lib/lafcadio/objectStore/SqlValueConverter.rb +0 -30
- data/lib/lafcadio/objectStore/SqlValueConverter.rb~ +0 -30
- data/lib/lafcadio/query/Compare.rb +0 -55
- data/lib/lafcadio/query/CompoundCondition.rb +0 -39
- data/lib/lafcadio/query/Condition.rb +0 -66
- data/lib/lafcadio/query/Condition.rb~ +0 -66
- data/lib/lafcadio/query/Equals.rb +0 -45
- data/lib/lafcadio/query/In.rb +0 -20
- data/lib/lafcadio/query/Like.rb +0 -48
- data/lib/lafcadio/query/Link.rb +0 -20
- data/lib/lafcadio/query/Max.rb +0 -32
- data/lib/lafcadio/query/Max.rb~ +0 -25
- data/lib/lafcadio/query/Not.rb +0 -21
- data/lib/lafcadio/query/Query.rb +0 -92
- data/lib/lafcadio/schema/CreateTableStatement.rb +0 -61
- data/lib/lafcadio/schema/CreateTableStatement.rb~ +0 -59
- data/lib/lafcadio/util/Context.rb +0 -61
- data/lib/lafcadio/util/ContextualService.rb +0 -33
- data/lib/lafcadio/util/English.rb +0 -117
- data/lib/lafcadio/util/HashOfArrays.rb +0 -48
- data/lib/lafcadio/util/LafcadioConfig.rb +0 -25
- data/lib/lafcadio/util/QueueHash.rb +0 -67
- data/lib/lafcadio/util/UsStates.rb +0 -29
- data/lib/lafcadio/xml.rb +0 -2
metadata
CHANGED
@@ -3,7 +3,7 @@ rubygems_version: 0.8.1
|
|
3
3
|
specification_version: 1
|
4
4
|
name: lafcadio
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.
|
6
|
+
version: 0.5.2
|
7
7
|
date: 2004-12-01
|
8
8
|
summary: Lafcadio is an object-relational mapping layer
|
9
9
|
require_paths:
|
@@ -12,7 +12,11 @@ author: Francis Hwang
|
|
12
12
|
email: sera@fhwang.net
|
13
13
|
homepage: http://lafcadio.rubyforge.org/
|
14
14
|
rubyforge_project:
|
15
|
-
description:
|
15
|
+
description: "Lafcadio is an object-relational mapping layer for Ruby and MySQL. It lets you
|
16
|
+
treat database rows like first-class Ruby objects, minimizing the amount of time
|
17
|
+
you have to spend thinking about MySQL vagaries so you can spend more time
|
18
|
+
thinking about your program's logic. It also offers extensive support for
|
19
|
+
unit-testing complex database logic without running cumbersome setup scripts."
|
16
20
|
autorequire: lafcadio
|
17
21
|
default_executable:
|
18
22
|
bindir: bin
|
@@ -29,97 +33,32 @@ files:
|
|
29
33
|
- lib/lafcadio
|
30
34
|
- lib/lafcadio.rb
|
31
35
|
- lib/lafcadio.rb~
|
32
|
-
- lib/lafcadio/dateTime
|
33
36
|
- lib/lafcadio/dateTime.rb
|
34
|
-
- lib/lafcadio/
|
37
|
+
- lib/lafcadio/dateTime.rb~
|
38
|
+
- lib/lafcadio/depend.rb
|
35
39
|
- lib/lafcadio/domain.rb
|
36
40
|
- lib/lafcadio/domain.rb~
|
37
|
-
- lib/lafcadio/includer.rb
|
38
|
-
- lib/lafcadio/mock
|
39
41
|
- lib/lafcadio/mock.rb
|
40
|
-
- lib/lafcadio/
|
42
|
+
- lib/lafcadio/mock.rb~
|
41
43
|
- lib/lafcadio/objectField.rb
|
42
|
-
- lib/lafcadio/
|
44
|
+
- lib/lafcadio/objectField.rb~
|
43
45
|
- lib/lafcadio/objectStore.rb
|
44
|
-
- lib/lafcadio/
|
46
|
+
- lib/lafcadio/objectStore.rb~
|
45
47
|
- lib/lafcadio/query.rb
|
46
|
-
- lib/lafcadio/
|
48
|
+
- lib/lafcadio/query.rb~
|
47
49
|
- lib/lafcadio/schema.rb
|
48
50
|
- lib/lafcadio/test
|
49
51
|
- lib/lafcadio/test.rb
|
52
|
+
- lib/lafcadio/test.rb~
|
50
53
|
- lib/lafcadio/TestSuite.rb
|
51
|
-
- lib/lafcadio/
|
54
|
+
- lib/lafcadio/TestSuite.rb~
|
52
55
|
- lib/lafcadio/util.rb
|
53
|
-
- lib/lafcadio/xml.rb
|
54
|
-
- lib/lafcadio/dateTime/Month.rb
|
55
|
-
- lib/lafcadio/domain/DomainObject.rb
|
56
|
-
- lib/lafcadio/domain/DomainObject.rb~
|
57
|
-
- lib/lafcadio/domain/MapObject.rb
|
58
|
-
- lib/lafcadio/domain/ObjectType.rb
|
59
|
-
- lib/lafcadio/mock/MockDbBridge.rb
|
60
|
-
- lib/lafcadio/mock/MockDbBridge.rb~
|
61
|
-
- lib/lafcadio/mock/MockObjectStore.rb
|
62
|
-
- lib/lafcadio/objectField/AutoIncrementField.rb
|
63
|
-
- lib/lafcadio/objectField/BooleanField.rb
|
64
|
-
- lib/lafcadio/objectField/DateField.rb
|
65
|
-
- lib/lafcadio/objectField/DateTimeField.rb
|
66
|
-
- lib/lafcadio/objectField/DecimalField.rb
|
67
|
-
- lib/lafcadio/objectField/EmailField.rb
|
68
|
-
- lib/lafcadio/objectField/EnumField.rb
|
69
|
-
- lib/lafcadio/objectField/FieldValueError.rb
|
70
|
-
- lib/lafcadio/objectField/IntegerField.rb
|
71
|
-
- lib/lafcadio/objectField/LinkField.rb
|
72
|
-
- lib/lafcadio/objectField/LinkField.rb~
|
73
|
-
- lib/lafcadio/objectField/MoneyField.rb
|
74
|
-
- lib/lafcadio/objectField/MonthField.rb
|
75
|
-
- lib/lafcadio/objectField/ObjectField.rb
|
76
|
-
- lib/lafcadio/objectField/PasswordField.rb
|
77
|
-
- lib/lafcadio/objectField/StateField.rb
|
78
|
-
- lib/lafcadio/objectField/SubsetLinkField.rb
|
79
|
-
- lib/lafcadio/objectField/TextField.rb
|
80
|
-
- lib/lafcadio/objectField/TextListField.rb
|
81
|
-
- lib/lafcadio/objectField/TimeStampField.rb
|
82
|
-
- lib/lafcadio/objectStore/Cache.rb
|
83
|
-
- lib/lafcadio/objectStore/Committer.rb
|
84
|
-
- lib/lafcadio/objectStore/CouldntMatchObjectTypeError.rb
|
85
|
-
- lib/lafcadio/objectStore/DbBridge.rb
|
86
|
-
- lib/lafcadio/objectStore/DbBridge.rb~
|
87
|
-
- lib/lafcadio/objectStore/DomainComparable.rb
|
88
|
-
- lib/lafcadio/objectStore/DomainObjectInitError.rb
|
89
|
-
- lib/lafcadio/objectStore/DomainObjectNotFoundError.rb
|
90
|
-
- lib/lafcadio/objectStore/DomainObjectProxy.rb
|
91
|
-
- lib/lafcadio/objectStore/DomainObjectSqlMaker.rb
|
92
|
-
- lib/lafcadio/objectStore/ObjectStore.rb
|
93
|
-
- lib/lafcadio/objectStore/ObjectStore.rb~
|
94
|
-
- lib/lafcadio/objectStore/SqlValueConverter.rb
|
95
|
-
- lib/lafcadio/objectStore/SqlValueConverter.rb~
|
96
|
-
- lib/lafcadio/query/Compare.rb
|
97
|
-
- lib/lafcadio/query/CompoundCondition.rb
|
98
|
-
- lib/lafcadio/query/Condition.rb
|
99
|
-
- lib/lafcadio/query/Condition.rb~
|
100
|
-
- lib/lafcadio/query/Equals.rb
|
101
|
-
- lib/lafcadio/query/In.rb
|
102
|
-
- lib/lafcadio/query/Like.rb
|
103
|
-
- lib/lafcadio/query/Link.rb
|
104
|
-
- lib/lafcadio/query/Max.rb
|
105
|
-
- lib/lafcadio/query/Max.rb~
|
106
|
-
- lib/lafcadio/query/Not.rb
|
107
|
-
- lib/lafcadio/query/Query.rb
|
108
|
-
- lib/lafcadio/schema/CreateTableStatement.rb
|
109
|
-
- lib/lafcadio/schema/CreateTableStatement.rb~
|
110
|
-
- lib/lafcadio/test/LafcadioTestCase.rb
|
111
56
|
- lib/lafcadio/test/testconfig.dat
|
112
|
-
- lib/lafcadio/util/Context.rb
|
113
|
-
- lib/lafcadio/util/ContextualService.rb
|
114
|
-
- lib/lafcadio/util/English.rb
|
115
|
-
- lib/lafcadio/util/HashOfArrays.rb
|
116
|
-
- lib/lafcadio/util/LafcadioConfig.rb
|
117
|
-
- lib/lafcadio/util/QueueHash.rb
|
118
|
-
- lib/lafcadio/util/UsStates.rb
|
119
57
|
test_files: []
|
120
58
|
rdoc_options: []
|
121
59
|
extra_rdoc_files: []
|
122
|
-
executables:
|
60
|
+
executables:
|
61
|
+
- lafcadio_schema
|
123
62
|
extensions: []
|
124
63
|
requirements: []
|
125
64
|
dependencies:
|
@@ -1,375 +0,0 @@
|
|
1
|
-
require 'lafcadio/objectField/LinkField'
|
2
|
-
require 'lafcadio/objectStore/DomainComparable'
|
3
|
-
require 'lafcadio/objectStore/DomainObjectProxy'
|
4
|
-
|
5
|
-
module Lafcadio
|
6
|
-
# All classes that correspond to a table in the database need to be children
|
7
|
-
# of DomainObject.
|
8
|
-
#
|
9
|
-
# = Defining fields
|
10
|
-
# There are two ways to define the fields of a DomainObject subclass.
|
11
|
-
# 1. Defining fields in an XML file. To do this,
|
12
|
-
# 1. Set one directory to contain all your XML files, by setting
|
13
|
-
# +classDefinitionDir+ in your LafcadioConfig file.
|
14
|
-
# 2. Write one XML file per domain class. For example, a User.xml file
|
15
|
-
# might look like:
|
16
|
-
# <lafcadio_class_definition name="User">
|
17
|
-
# <field name="lastName" class="TextField"/>
|
18
|
-
# <field name="email" class="TextField"/>
|
19
|
-
# <field name="password" class="TextField"/>
|
20
|
-
# <field name="birthday" class="DateField"/>
|
21
|
-
# </lafcadio_class_definition>
|
22
|
-
# 2. Overriding DomainObject.getClassFields. The method should return an Array
|
23
|
-
# of instances of ObjectField or its children. The order is unimportant.
|
24
|
-
# For example:
|
25
|
-
# class User < DomainObject
|
26
|
-
# def User.getClassFields
|
27
|
-
# fields = []
|
28
|
-
# fields << TextField.new(self, 'firstName')
|
29
|
-
# fields << TextField.new(self, 'lastName')
|
30
|
-
# fields << TextField.new(self, 'email')
|
31
|
-
# fields << TextField.new(self, 'password')
|
32
|
-
# fields << DateField.new(self, 'birthday')
|
33
|
-
# fields
|
34
|
-
# end
|
35
|
-
# end
|
36
|
-
#
|
37
|
-
# = Setting and retrieving fields
|
38
|
-
# Once your fields are defined, you can create an instance by passing in a
|
39
|
-
# hash of field names and values.
|
40
|
-
# john = User.new( 'firstName' => 'John', 'lastName' => 'Doe',
|
41
|
-
# 'email' => 'john.doe@email.com',
|
42
|
-
# 'password' => 'my_password',
|
43
|
-
# 'birthday' => tenYearsAgo )
|
44
|
-
#
|
45
|
-
# You can read and write these fields like normal instance attributes.
|
46
|
-
# john.email => 'john.doe@email.com'
|
47
|
-
# john.email = 'john.doe@mail.email.com'
|
48
|
-
#
|
49
|
-
# If your domain class has fields that refer to other domain classes, or even
|
50
|
-
# to another row in the same table, you can use a LinkField to express the
|
51
|
-
# relation.
|
52
|
-
# <lafcadio_class_definition name="Message">
|
53
|
-
# <field name="subject" class="TextField" />
|
54
|
-
# <field name="body" class="TextField" />
|
55
|
-
# <field name="author" class="LinkField" linkedType="User" />
|
56
|
-
# <field name="recipient" class="LinkField" linkedType="User" />
|
57
|
-
# <field name="dateSent" class="DateField" />
|
58
|
-
# </lafcadio_class_definition>
|
59
|
-
#
|
60
|
-
# msg = Message.new( 'subject' => 'hi there',
|
61
|
-
# 'body' => 'You wanna go to the movies on Saturday?',
|
62
|
-
# 'author' => john, 'recipient' => jane,
|
63
|
-
# 'dateSent' => Date.today )
|
64
|
-
#
|
65
|
-
# = pkId and committing
|
66
|
-
# Lafcadio requires that each table has a numeric primary key. It assumes that
|
67
|
-
# this key is named +pkId+ in the database, though that can be overridden.
|
68
|
-
#
|
69
|
-
# When you create a domain object by calling new, you should not assign a
|
70
|
-
# +pkId+ to the new instance. The pkId will automatically be set when you
|
71
|
-
# commit the object by calling DomainObject#commit.
|
72
|
-
#
|
73
|
-
# However, you may want to manually set +pkId+ when setting up a test case, so
|
74
|
-
# you can ensure that a domain object has a given primary key.
|
75
|
-
#
|
76
|
-
# = Naming assumptions, and how to override them
|
77
|
-
# By default, Lafcadio assumes that every domain object is indexed by the
|
78
|
-
# field +pkId+ in the database schema. If you're dealing with a table that
|
79
|
-
# uses a different field name, override DomainObject.sqlPrimaryKeyName.
|
80
|
-
# However, you will always use +pkId+ in your Ruby code.
|
81
|
-
#
|
82
|
-
# Lafcadio assumes that a domain class corresponds to a table whose name is
|
83
|
-
# the plural of the class name, and whose first letter is lowercase. A User
|
84
|
-
# class is assumed to be stored in a "users" table, while a ProductCategory
|
85
|
-
# class is assumed to be stored in a "productCategories" table. Override
|
86
|
-
# DomainObject.tableName to override this behavior.
|
87
|
-
#
|
88
|
-
# = Inheritance
|
89
|
-
# Domain classes can inherit from other domain classes; they have all the
|
90
|
-
# fields of any concrete superclasses plus any new fields defined for
|
91
|
-
# themselves. You can use normal inheritance to define this:
|
92
|
-
# class User < DomainObject
|
93
|
-
# ...
|
94
|
-
# end
|
95
|
-
#
|
96
|
-
# class Administrator < User
|
97
|
-
# ...
|
98
|
-
# end
|
99
|
-
#
|
100
|
-
# Lafcadio assumes that each concrete class has a corresponding table, and
|
101
|
-
# that each table has a +pkId+ field that is used to match rows between
|
102
|
-
# different levels.
|
103
|
-
class DomainObject
|
104
|
-
@@subclassHash = {}
|
105
|
-
@@classFields = {}
|
106
|
-
|
107
|
-
COMMIT_ADD = 1
|
108
|
-
COMMIT_EDIT = 2
|
109
|
-
COMMIT_DELETE = 3
|
110
|
-
|
111
|
-
include DomainComparable
|
112
|
-
|
113
|
-
def DomainObject.classFields #:nodoc:
|
114
|
-
classFields = @@classFields[self]
|
115
|
-
unless classFields
|
116
|
-
@@classFields[self] = self.getClassFields
|
117
|
-
classFields = @@classFields[self]
|
118
|
-
end
|
119
|
-
classFields
|
120
|
-
end
|
121
|
-
|
122
|
-
def DomainObject.abstractSubclasses #:nodoc:
|
123
|
-
require 'lafcadio/domain'
|
124
|
-
[ MapObject ]
|
125
|
-
end
|
126
|
-
|
127
|
-
def DomainObject.selfAndConcreteSuperclasses # :nodoc:
|
128
|
-
classes = [ ]
|
129
|
-
anObjectType = self
|
130
|
-
until(anObjectType == DomainObject ||
|
131
|
-
abstractSubclasses.index(anObjectType) != nil)
|
132
|
-
classes << anObjectType
|
133
|
-
anObjectType = anObjectType.superclass
|
134
|
-
end
|
135
|
-
classes
|
136
|
-
end
|
137
|
-
|
138
|
-
def DomainObject.method_missing(methodId) #:nodoc:
|
139
|
-
require 'lafcadio/domain'
|
140
|
-
ObjectType.getObjectType( self ).send( methodId.id2name )
|
141
|
-
end
|
142
|
-
|
143
|
-
def DomainObject.getClassField(fieldName) #:nodoc:
|
144
|
-
field = nil
|
145
|
-
self.classFields.each { |aField|
|
146
|
-
field = aField if aField.name == fieldName
|
147
|
-
}
|
148
|
-
field
|
149
|
-
end
|
150
|
-
|
151
|
-
def DomainObject.getClassFieldByDbFieldName( fieldName ) #:nodoc:
|
152
|
-
self.classFields.find { |field| field.dbFieldName == fieldName }
|
153
|
-
end
|
154
|
-
|
155
|
-
def DomainObject.getField( fieldName ) #:nodoc:
|
156
|
-
aDomainClass = self
|
157
|
-
field = nil
|
158
|
-
while aDomainClass < DomainObject && !field
|
159
|
-
field = aDomainClass.getClassField( fieldName )
|
160
|
-
aDomainClass = aDomainClass.superclass
|
161
|
-
end
|
162
|
-
if field
|
163
|
-
field
|
164
|
-
else
|
165
|
-
errStr = "Couldn't find field \"#{ field }\" in " +
|
166
|
-
"#{ self } domain class"
|
167
|
-
raise( MissingError, errStr, caller )
|
168
|
-
end
|
169
|
-
end
|
170
|
-
|
171
|
-
def DomainObject.dependentClasses #:nodoc:
|
172
|
-
dependentClasses = {}
|
173
|
-
DomainObject.subclasses.each { |aClass|
|
174
|
-
if aClass != DomainObjectProxy &&
|
175
|
-
(!DomainObject.abstractSubclasses.index(aClass))
|
176
|
-
aClass.classFields.each { |field|
|
177
|
-
if field.class <= LinkField && field.linkedType == self.objectType
|
178
|
-
dependentClasses[aClass] = field
|
179
|
-
end
|
180
|
-
}
|
181
|
-
end
|
182
|
-
}
|
183
|
-
dependentClasses
|
184
|
-
end
|
185
|
-
|
186
|
-
def DomainObject.objectType #:nodoc:
|
187
|
-
self
|
188
|
-
end
|
189
|
-
|
190
|
-
# Returns an array of all fields defined for this class and all concrete
|
191
|
-
# superclasses.
|
192
|
-
def DomainObject.allFields
|
193
|
-
allFields = []
|
194
|
-
selfAndConcreteSuperclasses.each { |aClass|
|
195
|
-
aClass.classFields.each { |field| allFields << field }
|
196
|
-
}
|
197
|
-
allFields
|
198
|
-
end
|
199
|
-
|
200
|
-
def DomainObject.inherited(subclass) #:nodoc:
|
201
|
-
@@subclassHash[subclass] = true
|
202
|
-
end
|
203
|
-
|
204
|
-
def DomainObject.subclasses #:nodoc:
|
205
|
-
@@subclassHash.keys
|
206
|
-
end
|
207
|
-
|
208
|
-
def DomainObject.isConcrete? #:nodoc:
|
209
|
-
(self != DomainObject && abstractSubclasses.index(self).nil?)
|
210
|
-
end
|
211
|
-
|
212
|
-
def DomainObject.isBasedOn? #:nodoc:
|
213
|
-
self.superclass.isConcrete?
|
214
|
-
end
|
215
|
-
|
216
|
-
def self.getDomainDirs #:nodoc:
|
217
|
-
config = LafcadioConfig.new
|
218
|
-
classPath = config['classpath']
|
219
|
-
domainDirStr = config['domainDirs']
|
220
|
-
if domainDirStr
|
221
|
-
domainDirs = domainDirStr.split(',')
|
222
|
-
else
|
223
|
-
domainDirs = [ classPath + 'domain/' ]
|
224
|
-
end
|
225
|
-
end
|
226
|
-
|
227
|
-
def self.getObjectTypeFromString(typeString) #:nodoc:
|
228
|
-
require 'lafcadio/objectStore/CouldntMatchObjectTypeError'
|
229
|
-
objectType = nil
|
230
|
-
typeString =~ /([^\:]*)$/
|
231
|
-
fileName = $1
|
232
|
-
getDomainDirs.each { |domainDir|
|
233
|
-
if Dir.entries(domainDir).index("#{fileName}.rb")
|
234
|
-
require "#{ domainDir }#{ fileName }"
|
235
|
-
end
|
236
|
-
}
|
237
|
-
if (domainFilesStr = LafcadioConfig.new['domainFiles'])
|
238
|
-
domainFilesStr.split(',').each { |domainFile|
|
239
|
-
require domainFile
|
240
|
-
}
|
241
|
-
end
|
242
|
-
subclasses.each { |subclass|
|
243
|
-
objectType = subclass if subclass.to_s == typeString
|
244
|
-
}
|
245
|
-
if objectType
|
246
|
-
objectType
|
247
|
-
else
|
248
|
-
raise CouldntMatchObjectTypeError,
|
249
|
-
"couldn't match objectType #{typeString}", caller
|
250
|
-
end
|
251
|
-
end
|
252
|
-
|
253
|
-
attr_accessor :errorMessages, :pkId, :lastCommit, :fields, :fields_set
|
254
|
-
attr_reader :delete
|
255
|
-
protected :fields, :fields_set
|
256
|
-
|
257
|
-
# fieldHash should contain key-value associations for the different
|
258
|
-
# fields of this domain class. For example, instantiating a User class
|
259
|
-
# might look like:
|
260
|
-
#
|
261
|
-
# User.new( 'firstNames' => 'John', 'lastName' => 'Doe',
|
262
|
-
# 'email' => 'john.doe@email.com', 'password' => 'l33t' )
|
263
|
-
#
|
264
|
-
# In normal usage any code you write that creates a domain object will not
|
265
|
-
# define the +pkId+ field. The system assumes that a domain object with an
|
266
|
-
# undefined +pkId+ has yet to be inserted into the database, and when you
|
267
|
-
# commit the domain object a +pkId+ will automatically be assigned.
|
268
|
-
#
|
269
|
-
# If you're creating mock objects for unit tests, you can explicitly set
|
270
|
-
# the +pkId+ to represent objects that already exist in the database.
|
271
|
-
def initialize(fieldHash)
|
272
|
-
@fieldHash = fieldHash
|
273
|
-
@pkId = fieldHash['pkId']
|
274
|
-
@pkId = @pkId.to_i unless @pkId.nil?
|
275
|
-
@errorMessages = []
|
276
|
-
@fields = {}
|
277
|
-
@fields_set = []
|
278
|
-
end
|
279
|
-
|
280
|
-
def method_missing( methId, *args ) #:nodoc:
|
281
|
-
if ( field = get_setter_field( methId ) )
|
282
|
-
set_field( field, args.first )
|
283
|
-
elsif ( field = get_getter_field( methId ) )
|
284
|
-
get_field( field )
|
285
|
-
else
|
286
|
-
super( methId, *args )
|
287
|
-
end
|
288
|
-
end
|
289
|
-
|
290
|
-
def get_getter_field( methId ) #:nodoc:
|
291
|
-
begin
|
292
|
-
self.class.getField( methId.id2name )
|
293
|
-
rescue MissingError
|
294
|
-
nil
|
295
|
-
end
|
296
|
-
end
|
297
|
-
|
298
|
-
def get_setter_field( methId ) #:nodoc:
|
299
|
-
if methId.id2name =~ /(.*)=$/
|
300
|
-
begin
|
301
|
-
self.class.getField( $1 )
|
302
|
-
rescue MissingError
|
303
|
-
nil
|
304
|
-
end
|
305
|
-
else
|
306
|
-
nil
|
307
|
-
end
|
308
|
-
end
|
309
|
-
|
310
|
-
def get_field( field ) #:nodoc:
|
311
|
-
unless @fields_set.include?( field )
|
312
|
-
set_field( field, @fieldHash[field.name] )
|
313
|
-
end
|
314
|
-
@fields[field.name]
|
315
|
-
end
|
316
|
-
|
317
|
-
def set_field( field, value ) #:nodoc:
|
318
|
-
if field.class <= LinkField
|
319
|
-
if value.class != DomainObjectProxy && value
|
320
|
-
value = DomainObjectProxy.new(value)
|
321
|
-
end
|
322
|
-
end
|
323
|
-
@fields[field.name] = value
|
324
|
-
@fields_set << field
|
325
|
-
end
|
326
|
-
|
327
|
-
# Returns the subclass of DomainObject that this instance represents.
|
328
|
-
# Because of the way that proxying works, clients should call this method
|
329
|
-
# instead of Object.class.
|
330
|
-
def objectType
|
331
|
-
self.class.objectType
|
332
|
-
end
|
333
|
-
|
334
|
-
# This template method is called before every commit. Subclasses can
|
335
|
-
# override it to ensure code is executed before a commit.
|
336
|
-
def preCommitTrigger
|
337
|
-
nil
|
338
|
-
end
|
339
|
-
|
340
|
-
# This template method is called after every commit. Subclasses can
|
341
|
-
# override it to ensure code is executed after a commit.
|
342
|
-
def postCommitTrigger
|
343
|
-
nil
|
344
|
-
end
|
345
|
-
|
346
|
-
# Set the delete value to true if you want this domain object to be deleted
|
347
|
-
# from the database during its next commit.
|
348
|
-
def delete=(value)
|
349
|
-
if value && !pkId
|
350
|
-
raise "No point deleting an object that's not already in the DB"
|
351
|
-
end
|
352
|
-
@delete = value
|
353
|
-
end
|
354
|
-
|
355
|
-
# By default, to_s is considered an invalid operation for domain objects,
|
356
|
-
# and will raise an error. This behavior can be overridden by subclasses.
|
357
|
-
def to_s
|
358
|
-
raise "Don't make me into a string unless the type asks"
|
359
|
-
end
|
360
|
-
|
361
|
-
# Returns a clone, with all of the fields copied.
|
362
|
-
def clone
|
363
|
-
copy = super
|
364
|
-
copy.fields = @fields.clone
|
365
|
-
copy.fields_set = @fields_set.clone
|
366
|
-
copy
|
367
|
-
end
|
368
|
-
|
369
|
-
# Commits this domain object to the database.
|
370
|
-
def commit
|
371
|
-
require 'lafcadio/objectStore/ObjectStore'
|
372
|
-
ObjectStore.getObjectStore.commit self
|
373
|
-
end
|
374
|
-
end
|
375
|
-
end
|