lafcadio 0.7.3 → 0.7.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/lafcadio.rb +1 -2
- data/lib/lafcadio.rb~ +1 -2
- data/lib/lafcadio/dateTime.rb~ +3 -3
- data/lib/lafcadio/depend.rb +5 -1
- data/lib/lafcadio/depend.rb~ +8 -0
- data/lib/lafcadio/domain.rb +92 -27
- data/lib/lafcadio/domain.rb~ +103 -27
- data/lib/lafcadio/mock.rb +28 -13
- data/lib/lafcadio/mock.rb~ +8 -4
- data/lib/lafcadio/objectField.rb +103 -103
- data/lib/lafcadio/objectField.rb~ +102 -99
- data/lib/lafcadio/objectStore.rb +11 -15
- data/lib/lafcadio/objectStore.rb~ +12 -14
- data/lib/lafcadio/query.rb +42 -16
- data/lib/lafcadio/query.rb~ +44 -23
- data/lib/lafcadio/schema.rb +4 -4
- data/lib/lafcadio/schema.rb~ +56 -0
- data/lib/lafcadio/test.rb +1 -1
- data/lib/lafcadio/test.rb~ +6 -1
- data/lib/lafcadio/util.rb +14 -297
- data/lib/lafcadio/util.rb~ +25 -210
- metadata +48 -6
- data/lib/lafcadio/dateTime.rb +0 -93
data/lib/lafcadio/mock.rb
CHANGED
@@ -8,6 +8,7 @@ module Lafcadio
|
|
8
8
|
@objects = {}
|
9
9
|
@retrievals_by_type = Hash.new 0
|
10
10
|
@query_count = Hash.new( 0 )
|
11
|
+
@next_pk_ids = {}
|
11
12
|
end
|
12
13
|
|
13
14
|
def commit(db_object)
|
@@ -53,17 +54,23 @@ module Lafcadio
|
|
53
54
|
end
|
54
55
|
|
55
56
|
def get_pk_id_before_committing( db_object )
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
57
|
+
if db_object.pk_id
|
58
|
+
db_object.pk_id
|
59
|
+
else
|
60
|
+
if ( next_pk_id = @next_pk_ids[db_object.domain_class] )
|
61
|
+
@last_pk_id_inserted = next_pk_id
|
62
|
+
@next_pk_ids[db_object.domain_class] = nil
|
63
|
+
next_pk_id
|
64
|
+
else
|
65
|
+
maxpk_id = 0
|
66
|
+
pk_ids = get_objects_by_domain_class( db_object.domain_class ).keys
|
67
|
+
pk_ids.each { |pk_id|
|
68
|
+
maxpk_id = pk_id if pk_id > maxpk_id
|
69
|
+
}
|
70
|
+
@last_pk_id_inserted = maxpk_id + 1
|
71
|
+
@last_pk_id_inserted
|
72
|
+
end
|
65
73
|
end
|
66
|
-
object_pk_id
|
67
74
|
end
|
68
75
|
|
69
76
|
def get_objects_by_domain_class( domain_class )
|
@@ -77,13 +84,21 @@ module Lafcadio
|
|
77
84
|
|
78
85
|
def group_query( query )
|
79
86
|
if query.class == Query::Max
|
80
|
-
|
81
|
-
|
87
|
+
dobjs_by_pk_id = @objects[query.domain_class]
|
88
|
+
if dobjs_by_pk_id
|
89
|
+
dobjs = dobjs_by_pk_id.values.sort_by { |dobj|
|
90
|
+
dobj.send( query.field_name )
|
91
|
+
}
|
92
|
+
[ dobjs.last.send( query.field_name ) ]
|
82
93
|
else
|
83
|
-
|
94
|
+
[ nil ]
|
84
95
|
end
|
85
96
|
end
|
86
97
|
end
|
98
|
+
|
99
|
+
def set_next_pk_id( domain_class, npi )
|
100
|
+
@next_pk_ids[ domain_class ] = npi
|
101
|
+
end
|
87
102
|
end
|
88
103
|
|
89
104
|
# Externally, the MockObjectStore looks and acts exactly like the ObjectStore,
|
data/lib/lafcadio/mock.rb~
CHANGED
@@ -47,7 +47,7 @@ module Lafcadio
|
|
47
47
|
objects = objects.sort_by { |dobj| dobj.pk_id }
|
48
48
|
end
|
49
49
|
if (range = query.limit)
|
50
|
-
objects = objects[range
|
50
|
+
objects = objects[range]
|
51
51
|
end
|
52
52
|
objects
|
53
53
|
end
|
@@ -77,10 +77,14 @@ module Lafcadio
|
|
77
77
|
|
78
78
|
def group_query( query )
|
79
79
|
if query.class == Query::Max
|
80
|
-
|
81
|
-
|
80
|
+
dobjs_by_pk_id = @objects[query.domain_class]
|
81
|
+
if dobjs_by_pk_id
|
82
|
+
dobjs = dobjs_by_pk_id.values.sort_by { |dobj|
|
83
|
+
dobj.send( query.field_name )
|
84
|
+
}
|
85
|
+
[ dobjs.last.send( query.field_name ) ]
|
82
86
|
else
|
83
|
-
|
87
|
+
[ nil ]
|
84
88
|
end
|
85
89
|
end
|
86
90
|
end
|
data/lib/lafcadio/objectField.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'date'
|
2
|
-
require 'lafcadio/
|
2
|
+
require 'lafcadio/depend'
|
3
3
|
require 'lafcadio/util'
|
4
4
|
|
5
5
|
module Lafcadio
|
@@ -113,16 +113,8 @@ module Lafcadio
|
|
113
113
|
end
|
114
114
|
end
|
115
115
|
|
116
|
-
#
|
117
|
-
class
|
118
|
-
def value_from_sql(string) #:nodoc:
|
119
|
-
value = super
|
120
|
-
value ? value.to_i : nil
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
# A TextField is expected to contain a string value.
|
125
|
-
class TextField < ObjectField
|
116
|
+
# A StringField is expected to contain a string value.
|
117
|
+
class StringField < ObjectField
|
126
118
|
def value_for_sql(value) #:nodoc:
|
127
119
|
if value
|
128
120
|
value = value.gsub(/(\\?')/) { |m| m.length == 1 ? "''" : m }
|
@@ -134,6 +126,14 @@ module Lafcadio
|
|
134
126
|
end
|
135
127
|
end
|
136
128
|
|
129
|
+
# IntegerField represents an integer.
|
130
|
+
class IntegerField < ObjectField
|
131
|
+
def value_from_sql(string) #:nodoc:
|
132
|
+
value = super
|
133
|
+
value ? value.to_i : nil
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
137
|
# BlobField stores a string value and expects to store its value in a BLOB
|
138
138
|
# field in the database.
|
139
139
|
class BlobField < ObjectField
|
@@ -269,30 +269,97 @@ module Lafcadio
|
|
269
269
|
dbi_value ? dbi_value.to_time : nil
|
270
270
|
end
|
271
271
|
end
|
272
|
-
|
273
|
-
#
|
274
|
-
class
|
272
|
+
|
273
|
+
# A DomainObjectField is used to link from one domain class to another.
|
274
|
+
class DomainObjectField < ObjectField
|
275
|
+
def self.auto_name( linked_type )
|
276
|
+
linked_type.name =~ /::/
|
277
|
+
( $' || linked_type.name ).camel_case_to_underscore
|
278
|
+
end
|
279
|
+
|
275
280
|
def self.instantiate_with_parameters( domain_class, parameters ) #:nodoc:
|
276
|
-
|
281
|
+
linked_type = parameters['linked_type']
|
282
|
+
instance = self.new(
|
283
|
+
domain_class, linked_type,
|
284
|
+
parameters['name'] || auto_name( linked_type ),
|
285
|
+
parameters['delete_cascade']
|
286
|
+
)
|
287
|
+
if parameters['db_field_name']
|
288
|
+
instance.db_field_name = parameters['db_field_name']
|
289
|
+
end
|
290
|
+
instance
|
277
291
|
end
|
278
292
|
|
279
|
-
def self.
|
280
|
-
|
293
|
+
def self.instantiation_parameters( fieldElt ) #:nodoc:
|
294
|
+
parameters = super( fieldElt )
|
295
|
+
linked_typeStr = fieldElt.attributes['linked_type']
|
296
|
+
linked_type = DomainObject.get_domain_class_from_string( linked_typeStr )
|
297
|
+
parameters['linked_type'] = linked_type
|
298
|
+
parameters['delete_cascade'] = fieldElt.attributes['delete_cascade'] == 'y'
|
299
|
+
parameters
|
281
300
|
end
|
282
301
|
|
283
|
-
|
284
|
-
|
285
|
-
|
302
|
+
attr_reader :linked_type
|
303
|
+
attr_accessor :delete_cascade
|
304
|
+
|
305
|
+
# [domain_class] The domain class that this field belongs to.
|
306
|
+
# [linked_type] The domain class that this field points to.
|
307
|
+
# [name] The name of this field.
|
308
|
+
# [delete_cascade] If this is true, deleting the domain object that is
|
309
|
+
# linked to will cause this domain object to be deleted
|
310
|
+
# as well.
|
311
|
+
def initialize( domain_class, linked_type, name = nil,
|
312
|
+
delete_cascade = false )
|
313
|
+
name = self.class.auto_name( linked_type ) unless name
|
314
|
+
super( domain_class, name )
|
315
|
+
( @linked_type, @delete_cascade ) = linked_type, delete_cascade
|
286
316
|
end
|
287
317
|
|
288
|
-
def value_from_sql(string
|
289
|
-
string != nil ? string.
|
318
|
+
def value_from_sql(string) #:nodoc:
|
319
|
+
string != nil ? DomainObjectProxy.new(@linked_type, string.to_i) : nil
|
320
|
+
end
|
321
|
+
|
322
|
+
def value_for_sql(value) #:nodoc:
|
323
|
+
if !value
|
324
|
+
"null"
|
325
|
+
elsif value.pk_id
|
326
|
+
value.pk_id
|
327
|
+
else
|
328
|
+
raise( DomainObjectInitError, "Can't commit #{name} without pk_id",
|
329
|
+
caller )
|
330
|
+
end
|
331
|
+
end
|
332
|
+
|
333
|
+
def verify_non_nil(value, pk_id) #:nodoc:
|
334
|
+
super
|
335
|
+
if @linked_type != @domain_class && pk_id
|
336
|
+
subsetDomainObjectField = @linked_type.class_fields.find { |field|
|
337
|
+
field.class == SubsetDomainObjectField && field.subset_field == @name
|
338
|
+
}
|
339
|
+
if subsetDomainObjectField
|
340
|
+
verify_subset_link_field( subsetDomainObjectField, pk_id )
|
341
|
+
end
|
342
|
+
end
|
343
|
+
end
|
344
|
+
|
345
|
+
def verify_subset_link_field( subsetDomainObjectField, pk_id )
|
346
|
+
begin
|
347
|
+
prevObj = ObjectStore.get_object_store.get( domain_class, pk_id )
|
348
|
+
prevObjLinkedTo = prevObj.send(name)
|
349
|
+
possiblyMyObj = prevObjLinkedTo.send(subsetDomainObjectField.name)
|
350
|
+
if possiblyMyObj && possiblyMyObj.pk_id == pk_id
|
351
|
+
cantChangeMsg = "You can't change that."
|
352
|
+
raise FieldValueError, cantChangeMsg, caller
|
353
|
+
end
|
354
|
+
rescue DomainObjectNotFoundError
|
355
|
+
# no previous value, so nothing to check for
|
356
|
+
end
|
290
357
|
end
|
291
358
|
end
|
292
359
|
|
293
360
|
# EmailField takes a text value that is expected to be formatted as a single
|
294
361
|
# valid email address.
|
295
|
-
class EmailField <
|
362
|
+
class EmailField < StringField
|
296
363
|
# Is +address+ a valid email address?
|
297
364
|
def self.valid_address(address)
|
298
365
|
address =~ /^[^ @]+@[^ \.]+\.[^ ,]+$/
|
@@ -327,7 +394,7 @@ module Lafcadio
|
|
327
394
|
# If you're defining the field in Ruby, you can simply pass in an array of
|
328
395
|
# enums as the +enums+ argument.
|
329
396
|
#
|
330
|
-
class EnumField <
|
397
|
+
class EnumField < StringField
|
331
398
|
def self.instantiate_with_parameters( domain_class, parameters ) #:nodoc:
|
332
399
|
self.new( domain_class, parameters['name'], parameters['enums'] )
|
333
400
|
end
|
@@ -388,90 +455,23 @@ module Lafcadio
|
|
388
455
|
class FieldValueError < RuntimeError #:nodoc:
|
389
456
|
end
|
390
457
|
|
391
|
-
#
|
392
|
-
class
|
393
|
-
def self.auto_name( linked_type )
|
394
|
-
linked_type.name =~ /::/
|
395
|
-
( $' || linked_type.name ).camel_case_to_underscore
|
396
|
-
end
|
397
|
-
|
458
|
+
# FloatField represents a decimal value.
|
459
|
+
class FloatField < ObjectField
|
398
460
|
def self.instantiate_with_parameters( domain_class, parameters ) #:nodoc:
|
399
|
-
|
400
|
-
instance = self.new(
|
401
|
-
domain_class, linked_type,
|
402
|
-
parameters['name'] || auto_name( linked_type ),
|
403
|
-
parameters['delete_cascade']
|
404
|
-
)
|
405
|
-
if parameters['db_field_name']
|
406
|
-
instance.db_field_name = parameters['db_field_name']
|
407
|
-
end
|
408
|
-
instance
|
409
|
-
end
|
410
|
-
|
411
|
-
def self.instantiation_parameters( fieldElt ) #:nodoc:
|
412
|
-
parameters = super( fieldElt )
|
413
|
-
linked_typeStr = fieldElt.attributes['linked_type']
|
414
|
-
linked_type = DomainObject.get_domain_class_from_string( linked_typeStr )
|
415
|
-
parameters['linked_type'] = linked_type
|
416
|
-
parameters['delete_cascade'] = fieldElt.attributes['delete_cascade'] == 'y'
|
417
|
-
parameters
|
418
|
-
end
|
419
|
-
|
420
|
-
attr_reader :linked_type
|
421
|
-
attr_accessor :delete_cascade
|
422
|
-
|
423
|
-
# [domain_class] The domain class that this field belongs to.
|
424
|
-
# [linked_type] The domain class that this field points to.
|
425
|
-
# [name] The name of this field.
|
426
|
-
# [delete_cascade] If this is true, deleting the domain object that is
|
427
|
-
# linked to will cause this domain object to be deleted
|
428
|
-
# as well.
|
429
|
-
def initialize( domain_class, linked_type, name = nil,
|
430
|
-
delete_cascade = false )
|
431
|
-
name = self.class.auto_name( linked_type ) unless name
|
432
|
-
super( domain_class, name )
|
433
|
-
( @linked_type, @delete_cascade ) = linked_type, delete_cascade
|
434
|
-
end
|
435
|
-
|
436
|
-
def value_from_sql(string) #:nodoc:
|
437
|
-
string != nil ? DomainObjectProxy.new(@linked_type, string.to_i) : nil
|
461
|
+
self.new( domain_class, parameters['name'] )
|
438
462
|
end
|
439
463
|
|
440
|
-
def
|
441
|
-
|
442
|
-
"null"
|
443
|
-
elsif value.pk_id
|
444
|
-
value.pk_id
|
445
|
-
else
|
446
|
-
raise( DomainObjectInitError, "Can't commit #{name} without pk_id",
|
447
|
-
caller )
|
448
|
-
end
|
464
|
+
def self.value_type #:nodoc:
|
465
|
+
Numeric
|
449
466
|
end
|
450
467
|
|
451
|
-
def
|
452
|
-
super
|
453
|
-
|
454
|
-
subsetLinkField = @linked_type.class_fields.find { |field|
|
455
|
-
field.class == SubsetLinkField && field.subset_field == @name
|
456
|
-
}
|
457
|
-
if subsetLinkField
|
458
|
-
verify_subset_link_field( subsetLinkField, pk_id )
|
459
|
-
end
|
460
|
-
end
|
468
|
+
def process_before_verify(value) #:nodoc:
|
469
|
+
value = super value
|
470
|
+
value != nil && value != '' ? value.to_f : nil
|
461
471
|
end
|
462
472
|
|
463
|
-
def
|
464
|
-
|
465
|
-
prevObj = ObjectStore.get_object_store.get( domain_class, pk_id )
|
466
|
-
prevObjLinkedTo = prevObj.send(name)
|
467
|
-
possiblyMyObj = prevObjLinkedTo.send(subsetLinkField.name)
|
468
|
-
if possiblyMyObj && possiblyMyObj.pk_id == pk_id
|
469
|
-
cantChangeMsg = "You can't change that."
|
470
|
-
raise FieldValueError, cantChangeMsg, caller
|
471
|
-
end
|
472
|
-
rescue DomainObjectNotFoundError
|
473
|
-
# no previous value, so nothing to check for
|
474
|
-
end
|
473
|
+
def value_from_sql(string, lookupLink = true) #:nodoc:
|
474
|
+
string != nil ? string.to_f : nil
|
475
475
|
end
|
476
476
|
end
|
477
477
|
|
@@ -499,11 +499,11 @@ module Lafcadio
|
|
499
499
|
# postal code.
|
500
500
|
class StateField < EnumField
|
501
501
|
def initialize( domain_class, name = "state" )
|
502
|
-
super( domain_class, name, UsStates.states )
|
502
|
+
super( domain_class, name, UsCommerce::UsStates.states )
|
503
503
|
end
|
504
504
|
end
|
505
505
|
|
506
|
-
class
|
506
|
+
class SubsetDomainObjectField < DomainObjectField #:nodoc:
|
507
507
|
def self.instantiate_with_parameters( domain_class, parameters )
|
508
508
|
self.new( domain_class, parameters['linked_type'],
|
509
509
|
parameters['subset_field'], parameters['name'] )
|
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'date'
|
2
|
-
require 'lafcadio/
|
2
|
+
require 'lafcadio/depend'
|
3
3
|
require 'lafcadio/util'
|
4
4
|
|
5
5
|
module Lafcadio
|
@@ -113,16 +113,8 @@ module Lafcadio
|
|
113
113
|
end
|
114
114
|
end
|
115
115
|
|
116
|
-
#
|
117
|
-
class
|
118
|
-
def value_from_sql(string) #:nodoc:
|
119
|
-
value = super
|
120
|
-
value ? value.to_i : nil
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
# A TextField is expected to contain a string value.
|
125
|
-
class TextField < ObjectField
|
116
|
+
# A StringField is expected to contain a string value.
|
117
|
+
class StringField < ObjectField
|
126
118
|
def value_for_sql(value) #:nodoc:
|
127
119
|
if value
|
128
120
|
value = value.gsub(/(\\?')/) { |m| m.length == 1 ? "''" : m }
|
@@ -134,6 +126,14 @@ module Lafcadio
|
|
134
126
|
end
|
135
127
|
end
|
136
128
|
|
129
|
+
# IntegerField represents an integer.
|
130
|
+
class IntegerField < ObjectField
|
131
|
+
def value_from_sql(string) #:nodoc:
|
132
|
+
value = super
|
133
|
+
value ? value.to_i : nil
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
137
|
# BlobField stores a string value and expects to store its value in a BLOB
|
138
138
|
# field in the database.
|
139
139
|
class BlobField < ObjectField
|
@@ -269,30 +269,97 @@ module Lafcadio
|
|
269
269
|
dbi_value ? dbi_value.to_time : nil
|
270
270
|
end
|
271
271
|
end
|
272
|
-
|
273
|
-
#
|
274
|
-
class
|
272
|
+
|
273
|
+
# A DomainObjectField is used to link from one domain class to another.
|
274
|
+
class DomainObjectField < ObjectField
|
275
|
+
def self.auto_name( linked_type )
|
276
|
+
linked_type.name =~ /::/
|
277
|
+
( $' || linked_type.name ).camel_case_to_underscore
|
278
|
+
end
|
279
|
+
|
275
280
|
def self.instantiate_with_parameters( domain_class, parameters ) #:nodoc:
|
276
|
-
|
281
|
+
linked_type = parameters['linked_type']
|
282
|
+
instance = self.new(
|
283
|
+
domain_class, linked_type,
|
284
|
+
parameters['name'] || auto_name( linked_type ),
|
285
|
+
parameters['delete_cascade']
|
286
|
+
)
|
287
|
+
if parameters['db_field_name']
|
288
|
+
instance.db_field_name = parameters['db_field_name']
|
289
|
+
end
|
290
|
+
instance
|
277
291
|
end
|
278
292
|
|
279
|
-
def self.
|
280
|
-
|
293
|
+
def self.instantiation_parameters( fieldElt ) #:nodoc:
|
294
|
+
parameters = super( fieldElt )
|
295
|
+
linked_typeStr = fieldElt.attributes['linked_type']
|
296
|
+
linked_type = DomainObject.get_domain_class_from_string( linked_typeStr )
|
297
|
+
parameters['linked_type'] = linked_type
|
298
|
+
parameters['delete_cascade'] = fieldElt.attributes['delete_cascade'] == 'y'
|
299
|
+
parameters
|
281
300
|
end
|
282
301
|
|
283
|
-
|
284
|
-
|
285
|
-
|
302
|
+
attr_reader :linked_type
|
303
|
+
attr_accessor :delete_cascade
|
304
|
+
|
305
|
+
# [domain_class] The domain class that this field belongs to.
|
306
|
+
# [linked_type] The domain class that this field points to.
|
307
|
+
# [name] The name of this field.
|
308
|
+
# [delete_cascade] If this is true, deleting the domain object that is
|
309
|
+
# linked to will cause this domain object to be deleted
|
310
|
+
# as well.
|
311
|
+
def initialize( domain_class, linked_type, name = nil,
|
312
|
+
delete_cascade = false )
|
313
|
+
name = self.class.auto_name( linked_type ) unless name
|
314
|
+
super( domain_class, name )
|
315
|
+
( @linked_type, @delete_cascade ) = linked_type, delete_cascade
|
286
316
|
end
|
287
317
|
|
288
|
-
def value_from_sql(string
|
289
|
-
string != nil ? string.
|
318
|
+
def value_from_sql(string) #:nodoc:
|
319
|
+
string != nil ? DomainObjectProxy.new(@linked_type, string.to_i) : nil
|
320
|
+
end
|
321
|
+
|
322
|
+
def value_for_sql(value) #:nodoc:
|
323
|
+
if !value
|
324
|
+
"null"
|
325
|
+
elsif value.pk_id
|
326
|
+
value.pk_id
|
327
|
+
else
|
328
|
+
raise( DomainObjectInitError, "Can't commit #{name} without pk_id",
|
329
|
+
caller )
|
330
|
+
end
|
331
|
+
end
|
332
|
+
|
333
|
+
def verify_non_nil(value, pk_id) #:nodoc:
|
334
|
+
super
|
335
|
+
if @linked_type != @domain_class && pk_id
|
336
|
+
subsetDomainObjectField = @linked_type.class_fields.find { |field|
|
337
|
+
field.class == SubsetDomainObjectField && field.subset_field == @name
|
338
|
+
}
|
339
|
+
if subsetDomainObjectField
|
340
|
+
verify_subset_link_field( subsetDomainObjectField, pk_id )
|
341
|
+
end
|
342
|
+
end
|
343
|
+
end
|
344
|
+
|
345
|
+
def verify_subset_link_field( subsetDomainObjectField, pk_id )
|
346
|
+
begin
|
347
|
+
prevObj = ObjectStore.get_object_store.get( domain_class, pk_id )
|
348
|
+
prevObjLinkedTo = prevObj.send(name)
|
349
|
+
possiblyMyObj = prevObjLinkedTo.send(subsetDomainObjectField.name)
|
350
|
+
if possiblyMyObj && possiblyMyObj.pk_id == pk_id
|
351
|
+
cantChangeMsg = "You can't change that."
|
352
|
+
raise FieldValueError, cantChangeMsg, caller
|
353
|
+
end
|
354
|
+
rescue DomainObjectNotFoundError
|
355
|
+
# no previous value, so nothing to check for
|
356
|
+
end
|
290
357
|
end
|
291
358
|
end
|
292
359
|
|
293
360
|
# EmailField takes a text value that is expected to be formatted as a single
|
294
361
|
# valid email address.
|
295
|
-
class EmailField <
|
362
|
+
class EmailField < StringField
|
296
363
|
# Is +address+ a valid email address?
|
297
364
|
def self.valid_address(address)
|
298
365
|
address =~ /^[^ @]+@[^ \.]+\.[^ ,]+$/
|
@@ -327,7 +394,7 @@ module Lafcadio
|
|
327
394
|
# If you're defining the field in Ruby, you can simply pass in an array of
|
328
395
|
# enums as the +enums+ argument.
|
329
396
|
#
|
330
|
-
class EnumField <
|
397
|
+
class EnumField < StringField
|
331
398
|
def self.instantiate_with_parameters( domain_class, parameters ) #:nodoc:
|
332
399
|
self.new( domain_class, parameters['name'], parameters['enums'] )
|
333
400
|
end
|
@@ -388,87 +455,23 @@ module Lafcadio
|
|
388
455
|
class FieldValueError < RuntimeError #:nodoc:
|
389
456
|
end
|
390
457
|
|
391
|
-
#
|
392
|
-
class
|
458
|
+
# FloatField represents a decimal value.
|
459
|
+
class FloatField < ObjectField
|
393
460
|
def self.instantiate_with_parameters( domain_class, parameters ) #:nodoc:
|
394
|
-
|
395
|
-
domain_class, parameters['linked_type'], parameters['name'],
|
396
|
-
parameters['delete_cascade']
|
397
|
-
)
|
398
|
-
if parameters['db_field_name']
|
399
|
-
instance.db_field_name = parameters['db_field_name']
|
400
|
-
end
|
401
|
-
instance
|
402
|
-
end
|
403
|
-
|
404
|
-
def self.instantiation_parameters( fieldElt ) #:nodoc:
|
405
|
-
parameters = super( fieldElt )
|
406
|
-
linked_typeStr = fieldElt.attributes['linked_type']
|
407
|
-
linked_type = DomainObject.get_domain_class_from_string( linked_typeStr )
|
408
|
-
parameters['linked_type'] = linked_type
|
409
|
-
parameters['delete_cascade'] = fieldElt.attributes['delete_cascade'] == 'y'
|
410
|
-
parameters
|
411
|
-
end
|
412
|
-
|
413
|
-
attr_reader :linked_type
|
414
|
-
attr_accessor :delete_cascade
|
415
|
-
|
416
|
-
# [domain_class] The domain class that this field belongs to.
|
417
|
-
# [linked_type] The domain class that this field points to.
|
418
|
-
# [name] The name of this field.
|
419
|
-
# [delete_cascade] If this is true, deleting the domain object that is
|
420
|
-
# linked to will cause this domain object to be deleted
|
421
|
-
# as well.
|
422
|
-
def initialize( domain_class, linked_type, name = nil,
|
423
|
-
delete_cascade = false )
|
424
|
-
unless name
|
425
|
-
linked_type.name =~ /::/
|
426
|
-
name = $' || linked_type.name
|
427
|
-
name = name.camel_case_to_underscore
|
428
|
-
end
|
429
|
-
super( domain_class, name )
|
430
|
-
( @linked_type, @delete_cascade ) = linked_type, delete_cascade
|
431
|
-
end
|
432
|
-
|
433
|
-
def value_from_sql(string) #:nodoc:
|
434
|
-
string != nil ? DomainObjectProxy.new(@linked_type, string.to_i) : nil
|
461
|
+
self.new( domain_class, parameters['name'] )
|
435
462
|
end
|
436
463
|
|
437
|
-
def
|
438
|
-
|
439
|
-
"null"
|
440
|
-
elsif value.pk_id
|
441
|
-
value.pk_id
|
442
|
-
else
|
443
|
-
raise( DomainObjectInitError, "Can't commit #{name} without pk_id",
|
444
|
-
caller )
|
445
|
-
end
|
464
|
+
def self.value_type #:nodoc:
|
465
|
+
Numeric
|
446
466
|
end
|
447
467
|
|
448
|
-
def
|
449
|
-
super
|
450
|
-
|
451
|
-
subsetLinkField = @linked_type.class_fields.find { |field|
|
452
|
-
field.class == SubsetLinkField && field.subset_field == @name
|
453
|
-
}
|
454
|
-
if subsetLinkField
|
455
|
-
verify_subset_link_field( subsetLinkField, pk_id )
|
456
|
-
end
|
457
|
-
end
|
468
|
+
def process_before_verify(value) #:nodoc:
|
469
|
+
value = super value
|
470
|
+
value != nil && value != '' ? value.to_f : nil
|
458
471
|
end
|
459
472
|
|
460
|
-
def
|
461
|
-
|
462
|
-
prevObj = ObjectStore.get_object_store.get( domain_class, pk_id )
|
463
|
-
prevObjLinkedTo = prevObj.send(name)
|
464
|
-
possiblyMyObj = prevObjLinkedTo.send(subsetLinkField.name)
|
465
|
-
if possiblyMyObj && possiblyMyObj.pk_id == pk_id
|
466
|
-
cantChangeMsg = "You can't change that."
|
467
|
-
raise FieldValueError, cantChangeMsg, caller
|
468
|
-
end
|
469
|
-
rescue DomainObjectNotFoundError
|
470
|
-
# no previous value, so nothing to check for
|
471
|
-
end
|
473
|
+
def value_from_sql(string, lookupLink = true) #:nodoc:
|
474
|
+
string != nil ? string.to_f : nil
|
472
475
|
end
|
473
476
|
end
|
474
477
|
|
@@ -500,7 +503,7 @@ module Lafcadio
|
|
500
503
|
end
|
501
504
|
end
|
502
505
|
|
503
|
-
class
|
506
|
+
class SubsetDomainObjectField < DomainObjectField #:nodoc:
|
504
507
|
def self.instantiate_with_parameters( domain_class, parameters )
|
505
508
|
self.new( domain_class, parameters['linked_type'],
|
506
509
|
parameters['subset_field'], parameters['name'] )
|