lafcadio 0.4.3 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. data/bin/lafcadio_schema +28 -0
  2. data/lib/lafcadio.rb +3 -4
  3. data/lib/lafcadio.rb~ +3 -4
  4. data/lib/lafcadio/TestSuite.rb +2 -0
  5. data/lib/lafcadio/TestSuite.rb~ +16 -0
  6. data/lib/lafcadio/dateTime.rb +93 -2
  7. data/lib/lafcadio/{dateTime/Month.rb → dateTime.rb~} +33 -33
  8. data/lib/lafcadio/depend.rb +3 -0
  9. data/lib/lafcadio/domain.rb +574 -70
  10. data/lib/lafcadio/domain.rb~ +570 -70
  11. data/lib/lafcadio/mock.rb +92 -2
  12. data/lib/lafcadio/mock.rb~ +93 -0
  13. data/lib/lafcadio/objectField.rb +614 -3
  14. data/lib/lafcadio/objectField.rb~ +618 -0
  15. data/lib/lafcadio/objectStore.rb +662 -19
  16. data/lib/lafcadio/objectStore.rb~ +746 -0
  17. data/lib/lafcadio/query.rb +415 -31
  18. data/lib/lafcadio/query.rb~ +572 -0
  19. data/lib/lafcadio/schema.rb +57 -2
  20. data/lib/lafcadio/test.rb +17 -2
  21. data/lib/lafcadio/{test/LafcadioTestCase.rb → test.rb~} +5 -5
  22. data/lib/lafcadio/test/testconfig.dat +1 -1
  23. data/lib/lafcadio/util.rb +337 -20
  24. metadata +16 -77
  25. data/lib/lafcadio/domain/DomainObject.rb +0 -375
  26. data/lib/lafcadio/domain/DomainObject.rb~ +0 -371
  27. data/lib/lafcadio/domain/MapObject.rb +0 -22
  28. data/lib/lafcadio/domain/ObjectType.rb +0 -80
  29. data/lib/lafcadio/includer.rb +0 -18
  30. data/lib/lafcadio/mock/MockDbBridge.rb +0 -78
  31. data/lib/lafcadio/mock/MockDbBridge.rb~ +0 -74
  32. data/lib/lafcadio/mock/MockObjectStore.rb +0 -20
  33. data/lib/lafcadio/objectField/AutoIncrementField.rb +0 -25
  34. data/lib/lafcadio/objectField/BooleanField.rb +0 -83
  35. data/lib/lafcadio/objectField/DateField.rb +0 -33
  36. data/lib/lafcadio/objectField/DateTimeField.rb +0 -25
  37. data/lib/lafcadio/objectField/DecimalField.rb +0 -41
  38. data/lib/lafcadio/objectField/EmailField.rb +0 -28
  39. data/lib/lafcadio/objectField/EnumField.rb +0 -62
  40. data/lib/lafcadio/objectField/FieldValueError.rb +0 -4
  41. data/lib/lafcadio/objectField/IntegerField.rb +0 -15
  42. data/lib/lafcadio/objectField/LinkField.rb +0 -92
  43. data/lib/lafcadio/objectField/LinkField.rb~ +0 -86
  44. data/lib/lafcadio/objectField/MoneyField.rb +0 -13
  45. data/lib/lafcadio/objectField/MonthField.rb +0 -16
  46. data/lib/lafcadio/objectField/ObjectField.rb +0 -142
  47. data/lib/lafcadio/objectField/PasswordField.rb +0 -29
  48. data/lib/lafcadio/objectField/StateField.rb +0 -13
  49. data/lib/lafcadio/objectField/SubsetLinkField.rb +0 -25
  50. data/lib/lafcadio/objectField/TextField.rb +0 -23
  51. data/lib/lafcadio/objectField/TextListField.rb +0 -21
  52. data/lib/lafcadio/objectField/TimeStampField.rb +0 -15
  53. data/lib/lafcadio/objectStore/Cache.rb +0 -81
  54. data/lib/lafcadio/objectStore/Committer.rb +0 -65
  55. data/lib/lafcadio/objectStore/CouldntMatchObjectTypeError.rb +0 -4
  56. data/lib/lafcadio/objectStore/DbBridge.rb +0 -140
  57. data/lib/lafcadio/objectStore/DbBridge.rb~ +0 -140
  58. data/lib/lafcadio/objectStore/DomainComparable.rb +0 -25
  59. data/lib/lafcadio/objectStore/DomainObjectInitError.rb +0 -9
  60. data/lib/lafcadio/objectStore/DomainObjectNotFoundError.rb +0 -4
  61. data/lib/lafcadio/objectStore/DomainObjectProxy.rb +0 -62
  62. data/lib/lafcadio/objectStore/DomainObjectSqlMaker.rb +0 -74
  63. data/lib/lafcadio/objectStore/ObjectStore.rb +0 -207
  64. data/lib/lafcadio/objectStore/ObjectStore.rb~ +0 -207
  65. data/lib/lafcadio/objectStore/SqlValueConverter.rb +0 -30
  66. data/lib/lafcadio/objectStore/SqlValueConverter.rb~ +0 -30
  67. data/lib/lafcadio/query/Compare.rb +0 -55
  68. data/lib/lafcadio/query/CompoundCondition.rb +0 -39
  69. data/lib/lafcadio/query/Condition.rb +0 -66
  70. data/lib/lafcadio/query/Condition.rb~ +0 -66
  71. data/lib/lafcadio/query/Equals.rb +0 -45
  72. data/lib/lafcadio/query/In.rb +0 -20
  73. data/lib/lafcadio/query/Like.rb +0 -48
  74. data/lib/lafcadio/query/Link.rb +0 -20
  75. data/lib/lafcadio/query/Max.rb +0 -32
  76. data/lib/lafcadio/query/Max.rb~ +0 -25
  77. data/lib/lafcadio/query/Not.rb +0 -21
  78. data/lib/lafcadio/query/Query.rb +0 -92
  79. data/lib/lafcadio/schema/CreateTableStatement.rb +0 -61
  80. data/lib/lafcadio/schema/CreateTableStatement.rb~ +0 -59
  81. data/lib/lafcadio/util/Context.rb +0 -61
  82. data/lib/lafcadio/util/ContextualService.rb +0 -33
  83. data/lib/lafcadio/util/English.rb +0 -117
  84. data/lib/lafcadio/util/HashOfArrays.rb +0 -48
  85. data/lib/lafcadio/util/LafcadioConfig.rb +0 -25
  86. data/lib/lafcadio/util/QueueHash.rb +0 -67
  87. data/lib/lafcadio/util/UsStates.rb +0 -29
  88. data/lib/lafcadio/xml.rb +0 -2
@@ -1,18 +0,0 @@
1
- class Includer # :nodoc:
2
- def Includer.include( subdir )
3
- dir = nil
4
- $:.each { |includeDir|
5
- attemptedDir = includeDir + '/lafcadio/' + subdir
6
- begin
7
- dir = Dir.open( attemptedDir )
8
- rescue Errno::ENOENT
9
- # wrong include directory, try again
10
- end
11
- }
12
- if dir
13
- dir.entries.each { |entry|
14
- require "lafcadio/#{ subdir }/#{ $1 }" if entry =~ /(.*)\.rb/
15
- }
16
- end
17
- end
18
- end
@@ -1,78 +0,0 @@
1
- module Lafcadio
2
- class MockDbBridge #:nodoc:
3
- attr_reader :lastPkIdInserted, :retrievalsByType, :query_count
4
-
5
- def initialize
6
- @objects = {}
7
- @retrievalsByType = Hash.new 0
8
- @query_count = Hash.new( 0 )
9
- end
10
-
11
- def addObject(dbObject)
12
- commit dbObject
13
- end
14
-
15
- def commit(dbObject)
16
- objectsByObjectType = @objects[dbObject.objectType]
17
- unless objectsByObjectType
18
- objectsByObjectType = {}
19
- @objects[dbObject.objectType] = objectsByObjectType
20
- end
21
- if dbObject.delete
22
- objectsByObjectType.delete dbObject.pkId
23
- else
24
- object_pkId = dbObject.pkId
25
- unless object_pkId
26
- maxpkId = 0
27
- objectsByObjectType.keys.each { |pkId|
28
- maxpkId = pkId if pkId > maxpkId
29
- }
30
- @lastPkIdInserted = maxpkId + 1
31
- object_pkId = @lastPkIdInserted
32
- end
33
- objectsByObjectType[object_pkId] = dbObject
34
- end
35
- end
36
-
37
- def collection(objectType, objects); objects; end
38
-
39
- def _getAll(objectType)
40
- @retrievalsByType[objectType] = @retrievalsByType[objectType] + 1
41
- @objects[objectType] ? @objects[objectType].values : []
42
- end
43
-
44
- def getCollectionByQuery(query)
45
- @query_count[query] += 1
46
- objectType = query.objectType
47
- condition = query.condition
48
- objects = []
49
- _getAll( objectType ).each { |dbObj|
50
- if condition
51
- objects << dbObj if condition.objectMeets(dbObj)
52
- else
53
- objects << dbObj
54
- end
55
- }
56
- coll = collection( objectType, objects )
57
- if (range = query.limit)
58
- coll = coll[0..(range.last - range.first)]
59
- end
60
- if ( order_by = query.orderBy )
61
- coll = coll.sort_by { |dobj| dobj.send( order_by ) }
62
- coll.reverse! if query.orderByOrder == Query::DESC
63
- end
64
- coll
65
- end
66
-
67
- def group_query( query )
68
- if query.class == Query::Max
69
- if ( query.field_name == query.objectType.sqlPrimaryKeyName ||
70
- query.field_name == 'rate' )
71
- query.collect( @objects[query.objectType].values )
72
- else
73
- raise "Can't handle query with sql '#{ query.toSql }'"
74
- end
75
- end
76
- end
77
- end
78
- end
@@ -1,74 +0,0 @@
1
- module Lafcadio
2
- class MockDbBridge #:nodoc:
3
- attr_reader :lastPkIdInserted, :retrievalsByType, :query_count
4
-
5
- def initialize
6
- @objects = {}
7
- @retrievalsByType = Hash.new 0
8
- @query_count = Hash.new( 0 )
9
- end
10
-
11
- def addObject(dbObject)
12
- commit dbObject
13
- end
14
-
15
- def commit(dbObject)
16
- objectsByObjectType = @objects[dbObject.objectType]
17
- unless objectsByObjectType
18
- objectsByObjectType = {}
19
- @objects[dbObject.objectType] = objectsByObjectType
20
- end
21
- if dbObject.delete
22
- objectsByObjectType.delete dbObject.pkId
23
- else
24
- object_pkId = dbObject.pkId
25
- unless object_pkId
26
- maxpkId = 0
27
- objectsByObjectType.keys.each { |pkId|
28
- maxpkId = pkId if pkId > maxpkId
29
- }
30
- @lastPkIdInserted = maxpkId + 1
31
- object_pkId = @lastPkIdInserted
32
- end
33
- objectsByObjectType[object_pkId] = dbObject
34
- end
35
- end
36
-
37
- def collection(objectType, objects); objects; end
38
-
39
- def _getAll(objectType)
40
- @retrievalsByType[objectType] = @retrievalsByType[objectType] + 1
41
- @objects[objectType] ? @objects[objectType].values : []
42
- end
43
-
44
- def getCollectionByQuery(query)
45
- @query_count[query] += 1
46
- objectType = query.objectType
47
- condition = query.condition
48
- objects = []
49
- _getAll( objectType ).each { |dbObj|
50
- if condition
51
- objects << dbObj if condition.objectMeets(dbObj)
52
- else
53
- objects << dbObj
54
- end
55
- }
56
- coll = collection( objectType, objects )
57
- if (range = query.limit)
58
- coll = coll[0..(range.last - range.first)]
59
- end
60
- coll
61
- end
62
-
63
- def group_query( query )
64
- if query.class == Query::Max
65
- if ( query.field_name == query.objectType.sqlPrimaryKeyName ||
66
- query.field_name == 'rate' )
67
- query.collect( @objects[query.objectType].values )
68
- else
69
- raise "Can't handle query with sql '#{ query.toSql }'"
70
- end
71
- end
72
- end
73
- end
74
- end
@@ -1,20 +0,0 @@
1
- require 'lafcadio/objectStore/ObjectStore'
2
- require 'lafcadio/mock/MockDbBridge'
3
-
4
- module Lafcadio
5
- # Externally, the MockObjectStore looks and acts exactly like the ObjectStore,
6
- # but stores all its data in memory. This makes it very useful for unit
7
- # testing, and in fact LafcadioTestCase#setup creates a new instance of
8
- # MockObjectStore for each test case.
9
- class MockObjectStore < ObjectStore
10
- public_class_method :new
11
-
12
- def initialize(context) # :nodoc:
13
- super(context, MockDbBridge.new)
14
- end
15
-
16
- def addObject(dbObject) # :nodoc:
17
- commit dbObject
18
- end
19
- end
20
- end
@@ -1,25 +0,0 @@
1
- require 'lafcadio/objectField/IntegerField'
2
-
3
- module Lafcadio
4
- class AutoIncrementField < IntegerField # :nodoc:
5
- attr_reader :objectType
6
-
7
- def initialize(objectType, name, englishName = nil)
8
- super(objectType, name, englishName)
9
- @objectType = objectType
10
- end
11
-
12
- def HTMLWidgetValueStr(value)
13
- if value != nil
14
- super value
15
- else
16
- highestValue = 0
17
- ObjectStore.getObjectStore.getAll(objectType).each { |obj|
18
- aValue = obj.send(name).to_i
19
- highestValue = aValue if aValue > highestValue
20
- }
21
- (highestValue + 1).to_s
22
- end
23
- end
24
- end
25
- end
@@ -1,83 +0,0 @@
1
- require 'lafcadio/objectField/ObjectField'
2
-
3
- module Lafcadio
4
- # BooleanField represents a boolean value. By default, it assumes that the
5
- # table field represents True and False with the integers 1 and 0. There are
6
- # two different ways to change this default.
7
- #
8
- # First, BooleanField includes a few enumerated defaults. Currently there are
9
- # only
10
- # * BooleanField::ENUMS_ONE_ZERO (the default, uses integers 1 and 0)
11
- # * BooleanField::ENUMS_CAPITAL_YES_NO (uses characters 'Y' and 'N')
12
- # In the XML class definition, this field would look like
13
- # <field name="field_name" class="BooleanField"
14
- # enumType="ENUMS_CAPITAL_YES_NO"/>
15
- # If you're defining a field in Ruby, simply set BooleanField#enumType to one
16
- # of the values.
17
- #
18
- # For more fine-grained specification you can pass specific values in. Use
19
- # this format for the XML class definition:
20
- # <field name="field_name" class="BooleanField">
21
- # <enums>
22
- # <enum key="true">yin</enum>
23
- # <enum key="false">tang</enum>
24
- # </enums>
25
- # </field>
26
- # If you're defining the field in Ruby, set BooleanField#enums to a hash.
27
- # myBooleanField.enums = { true => 'yin', false => 'yang' }
28
- #
29
- # +enums+ takes precedence over +enumType+.
30
- class BooleanField < ObjectField
31
- ENUMS_ONE_ZERO = 0
32
- ENUMS_CAPITAL_YES_NO = 1
33
-
34
- attr_accessor :enumType, :enums
35
-
36
- def initialize(objectType, name, englishName = nil)
37
- super(objectType, name, englishName)
38
- @enumType = ENUMS_ONE_ZERO
39
- @enums = nil
40
- end
41
-
42
- def getEnums( value = nil ) # :nodoc:
43
- if @enums
44
- @enums
45
- elsif @enumType == ENUMS_ONE_ZERO
46
- if value.class == String
47
- { true => '1', false => '0' }
48
- else
49
- { true => 1, false => 0 }
50
- end
51
- elsif @enumType == ENUMS_CAPITAL_YES_NO
52
- { true => 'Y', false => 'N' }
53
- else
54
- raise MissingError
55
- end
56
- end
57
-
58
- def trueEnum( value = nil ) # :nodoc:
59
- getEnums( value )[true]
60
- end
61
-
62
- def falseEnum # :nodoc:
63
- getEnums[false]
64
- end
65
-
66
- def textEnumType # :nodoc:
67
- @enums ? @enums[true].class == String : @enumType == ENUMS_CAPITAL_YES_NO
68
- end
69
-
70
- def valueForSQL(value) # :nodoc:
71
- if value
72
- vfs = trueEnum
73
- else
74
- vfs = falseEnum
75
- end
76
- textEnumType ? "'#{vfs}'" : vfs
77
- end
78
-
79
- def valueFromSQL(value, lookupLink = true) # :nodoc:
80
- value == trueEnum( value )
81
- end
82
- end
83
- end
@@ -1,33 +0,0 @@
1
- require 'lafcadio/objectField/ObjectField'
2
- require 'date'
3
-
4
- module Lafcadio
5
- # DateField represents a Date.
6
- class DateField < ObjectField
7
- RANGE_NEAR_FUTURE = 0
8
- RANGE_PAST = 1
9
-
10
- def DateField.valueType # :nodoc:
11
- Date
12
- end
13
-
14
- attr_accessor :range
15
-
16
- def initialize(objectType, name = "date", englishName = nil)
17
- super(objectType, name, englishName)
18
- @range = RANGE_NEAR_FUTURE
19
- end
20
-
21
- def valueForSQL(value) # :nodoc:
22
- value ? "'#{value.to_s}'" : 'null'
23
- end
24
-
25
- def valueFromSQL(dbiDate, lookupLink = true) # :nodoc:
26
- begin
27
- dbiDate ? dbiDate.to_date : nil
28
- rescue ArgumentError
29
- nil
30
- end
31
- end
32
- end
33
- end
@@ -1,25 +0,0 @@
1
- require 'lafcadio/util'
2
- require 'lafcadio/objectField/ObjectField'
3
-
4
- module Lafcadio
5
- # DateTimeField represents a DateTime.
6
- class DateTimeField < ObjectField
7
- def valueFromSQL(dbi_value, lookupLink = true) # :nodoc:
8
- dbi_value ? dbi_value.to_time : nil
9
- end
10
-
11
- def valueForSQL(value) # :nodoc:
12
- if value
13
- year = value.year
14
- month = value.mon.to_s.pad( 2, "0" )
15
- day = value.day.to_s.pad( 2, "0" )
16
- hour = value.hour.to_s.pad( 2, "0" )
17
- minute = value.min.to_s.pad( 2, "0" )
18
- second = value.sec.to_s.pad( 2, "0" )
19
- "'#{year}-#{month}-#{day} #{hour}:#{minute}:#{second}'"
20
- else
21
- "null"
22
- end
23
- end
24
- end
25
- end
@@ -1,41 +0,0 @@
1
- require 'lafcadio/objectField/ObjectField'
2
-
3
- module Lafcadio
4
- # DecimalField represents a decimal value.
5
- class DecimalField < ObjectField
6
- attr_reader :precision
7
-
8
- def DecimalField.valueType #:nodoc:
9
- Numeric
10
- end
11
-
12
- def DecimalField.instantiationParameters( fieldElt ) #:nodoc:
13
- parameters = super( fieldElt )
14
- parameters['precision'] = fieldElt.attributes['precision'].to_i
15
- parameters
16
- end
17
-
18
- def self.instantiateWithParameters( domainClass, parameters ) #:nodoc:
19
- self.new( domainClass, parameters['name'], parameters['precision'],
20
- parameters['englishName'] )
21
- end
22
-
23
- # [objectType] The domain class that this field belongs to.
24
- # [name] The name of this field.
25
- # [precision] The expected field precision. (Deprecated)
26
- # [englishName] The English name of this field. (Deprecated)
27
- def initialize(objectType, name, precision, englishName = nil)
28
- super(objectType, name, englishName)
29
- @precision = precision
30
- end
31
-
32
- def valueFromSQL(string, lookupLink = true) #:nodoc:
33
- string != nil ? string.to_f : nil
34
- end
35
-
36
- def processBeforeVerify(value) #:nodoc:
37
- value = super value
38
- value != nil && value != '' ? value.to_f : nil
39
- end
40
- end
41
- end
@@ -1,28 +0,0 @@
1
- require 'lafcadio/objectField/TextField'
2
- require 'lafcadio/objectField/FieldValueError'
3
-
4
- module Lafcadio
5
- # EmailField takes a text value that is expected to be formatted as a single
6
- # valid email address.
7
- class EmailField < TextField
8
- # Is +address+ a valid email address?
9
- def EmailField.validAddress(address)
10
- address =~ /^[^ @]+@[^ \.]+\.[^ ,]+$/
11
- end
12
-
13
- def initialize(objectType, name = "email", englishName = nil)
14
- super(objectType, name, englishName)
15
- end
16
-
17
- def nullErrorMsg #:nodoc:
18
- "Please enter an email address."
19
- end
20
-
21
- def verify(value, pkId) #:nodoc:
22
- super(value, pkId)
23
- if !EmailField.validAddress(value)
24
- raise FieldValueError, "Please enter a valid email address.", caller
25
- end
26
- end
27
- end
28
- end
@@ -1,62 +0,0 @@
1
- require 'lafcadio/objectField/TextField'
2
-
3
- module Lafcadio
4
- # EnumField represents an enumerated field that can only be set to one of a
5
- # set range of string values. To set the enumeration in the class definition
6
- # XML, use the following format:
7
- # <field name="flavor" class="EnumField">
8
- # <enums>
9
- # <enum>Vanilla</enum>
10
- # <enum>Chocolate</enum>
11
- # <enum>Lychee</enum>
12
- # </enums>
13
- # </field>
14
- # If you're defining the field in Ruby, you can simply pass in an array of
15
- # enums as the +enums+ argument.
16
- #
17
- class EnumField < TextField
18
- def EnumField.instantiationParameters( fieldElt ) #:nodoc:
19
- parameters = super( fieldElt )
20
- if fieldElt.elements['enums'][1].attributes['key']
21
- enumValues = []
22
- fieldElt.elements.each( 'enums/enum' ) { |enumElt|
23
- enumValues << enumElt.attributes['key']
24
- enumValues << enumElt.text.to_s
25
- }
26
- parameters['enums'] = QueueHash.new( *enumValues )
27
- else
28
- parameters['enums'] = []
29
- fieldElt.elements.each( 'enums/enum' ) { |enumElt|
30
- parameters['enums'] << enumElt.text.to_s
31
- }
32
- end
33
- parameters
34
- end
35
-
36
- def EnumField.instantiateWithParameters( domainClass, parameters ) #:nodoc:
37
- self.new( domainClass, parameters['name'], parameters['enums'],
38
- parameters['englishName'] )
39
- end
40
-
41
- attr_reader :enums
42
-
43
- # [objectType] The domain class that this field belongs to.
44
- # [name] The name of this domain class.
45
- # [enums] An array of Strings representing the possible choices for
46
- # this field.
47
- # [englishName] The English name of this field. (Deprecated)
48
- def initialize(objectType, name, enums, englishName = nil)
49
- require 'lafcadio/util/QueueHash'
50
- super objectType, name, englishName
51
- if enums.class == Array
52
- @enums = QueueHash.newFromArray enums
53
- else
54
- @enums = enums
55
- end
56
- end
57
-
58
- def valueForSQL(value) #:nodoc:
59
- value != '' ?(super(value)) : 'null'
60
- end
61
- end
62
- end