lafcadio 0.6.4 → 0.6.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -16,7 +16,7 @@
16
16
  # http://lafcadio.rubyforge.org/tutorial.html.
17
17
 
18
18
  module Lafcadio
19
- Version = "0.6.4"
19
+ Version = "0.6.5"
20
20
 
21
21
  require 'lafcadio/dateTime'
22
22
  require 'lafcadio/depend'
@@ -16,7 +16,7 @@
16
16
  # http://lafcadio.rubyforge.org/tutorial.html.
17
17
 
18
18
  module Lafcadio
19
- Version = "0.6.3"
19
+ Version = "0.6.4"
20
20
 
21
21
  require 'lafcadio/dateTime'
22
22
  require 'lafcadio/depend'
@@ -278,6 +278,13 @@ module Lafcadio
278
278
  unless class_fields
279
279
  @@class_fields[self] = self.get_class_fields
280
280
  class_fields = @@class_fields[self]
281
+ class_fields.each do |class_field|
282
+ begin
283
+ undef_method class_field.name.to_sym
284
+ rescue NameError
285
+ # not defined globally or in an included Module, skip it
286
+ end
287
+ end
281
288
  end
282
289
  class_fields
283
290
  end
@@ -288,13 +295,15 @@ module Lafcadio
288
295
  class_fields = [ @@pk_fields[self] ]
289
296
  @@class_fields[self] = class_fields
290
297
  end
291
- att_hash['name'] = name
292
- field = field_class.instantiate_with_parameters( self, att_hash )
293
- att_hash.each { |field_name, value|
294
- setter = field_name + '='
295
- field.send( setter, value ) if field.respond_to?( setter )
296
- }
297
- class_fields << field
298
+ unless class_fields.any? { |cf| cf.name == name }
299
+ att_hash['name'] = name
300
+ field = field_class.instantiate_with_parameters( self, att_hash )
301
+ att_hash.each { |field_name, value|
302
+ setter = field_name + '='
303
+ field.send( setter, value ) if field.respond_to?( setter )
304
+ }
305
+ class_fields << field
306
+ end
298
307
  end
299
308
 
300
309
  def self.dependent_classes #:nodoc:
@@ -278,6 +278,13 @@ module Lafcadio
278
278
  unless class_fields
279
279
  @@class_fields[self] = self.get_class_fields
280
280
  class_fields = @@class_fields[self]
281
+ class_fields.each do |class_field|
282
+ begin
283
+ undef_method class_field.name.to_sym
284
+ rescue NameError
285
+ # not defined globally or in an included Module, skip it
286
+ end
287
+ end
281
288
  end
282
289
  class_fields
283
290
  end
@@ -330,6 +337,8 @@ module Lafcadio
330
337
  def self.get_class_fields
331
338
  if self.methods( false ).include?( 'get_class_fields' )
332
339
  [ @@pk_fields[ self ] ]
340
+ elsif abstract_subclasses.include?( self )
341
+ []
333
342
  else
334
343
  xmlParser = try_load_xml_parser
335
344
  if xmlParser
@@ -74,10 +74,14 @@ module Lafcadio
74
74
 
75
75
  def group_query( query )
76
76
  if query.class == Query::Max
77
- if ( query.field_name == 'pk_id' || query.field_name == 'rate' )
78
- query.collect( @objects[query.domain_class].values )
77
+ dobjs_by_pk_id = @objects[query.domain_class]
78
+ if dobjs_by_pk_id
79
+ dobjs = dobjs_by_pk_id.values.sort_by { |dobj|
80
+ dobj.send( query.field_name )
81
+ }
82
+ [ dobjs.last.send( query.field_name ) ]
79
83
  else
80
- raise "Can't handle query with sql '#{ query.to_sql }'"
84
+ [ nil ]
81
85
  end
82
86
  end
83
87
  end
@@ -44,7 +44,7 @@ module Lafcadio
44
44
  objects = objects.sort_by { |dobj| dobj.pk_id }
45
45
  end
46
46
  if (range = query.limit)
47
- objects = objects[0..(range.last - range.first)]
47
+ objects = objects[range]
48
48
  end
49
49
  objects
50
50
  end
@@ -11,9 +11,10 @@ module Lafcadio
11
11
 
12
12
  attr_reader :commit_type, :db_object
13
13
 
14
- def initialize(db_object, dbBridge)
14
+ def initialize(db_object, dbBridge, cache)
15
15
  @db_object = db_object
16
16
  @dbBridge = dbBridge
17
+ @cache = cache
17
18
  @objectStore = ObjectStore.get_object_store
18
19
  @commit_type = nil
19
20
  end
@@ -28,6 +29,7 @@ module Lafcadio
28
29
  unless @db_object.pk_id
29
30
  @db_object.pk_id = @dbBridge.last_pk_id_inserted
30
31
  end
32
+ @cache.update_after_commit self
31
33
  @db_object.post_commit_trigger
32
34
  end
33
35
 
@@ -129,12 +131,8 @@ module Lafcadio
129
131
 
130
132
  def group_query( query )
131
133
  execute_select( query.to_sql )[0].collect { |val|
132
- if query.field_name != query.domain_class.sql_primary_key_name
133
- a_field = query.domain_class.get_field( query.field_name )
134
- a_field.value_from_sql( val )
135
- else
136
- val.to_i
137
- end
134
+ a_field = query.domain_class.get_field( query.field_name )
135
+ a_field.value_from_sql( val )
138
136
  }
139
137
  end
140
138
 
@@ -540,9 +538,8 @@ module Lafcadio
540
538
  end
541
539
 
542
540
  def commit( db_object )
543
- committer = Committer.new db_object, @dbBridge
541
+ committer = Committer.new db_object, @dbBridge, self
544
542
  committer.execute
545
- update_after_commit( committer )
546
543
  end
547
544
 
548
545
  # Flushes a domain object.
@@ -129,12 +129,8 @@ module Lafcadio
129
129
 
130
130
  def group_query( query )
131
131
  execute_select( query.to_sql )[0].collect { |val|
132
- if query.field_name != query.domain_class.sql_primary_key_name
133
- a_field = query.domain_class.get_field( query.field_name )
134
- a_field.value_from_sql( val )
135
- else
136
- val.to_i
137
- end
132
+ a_field = query.domain_class.get_field( query.field_name )
133
+ a_field.value_from_sql( val )
138
134
  }
139
135
  end
140
136
 
@@ -443,7 +439,7 @@ module Lafcadio
443
439
  def get_db_bridge; @dbBridge; end
444
440
 
445
441
  def get_field_name( domain_object )
446
- domain_object.domain_class.basename.decapitalize
442
+ domain_object.domain_class.basename.camel_case_to_underscore
447
443
  end
448
444
 
449
445
  def get_filtered(domain_class_name, searchTerm, fieldName = nil) #:nodoc:
@@ -273,15 +273,17 @@ module Lafcadio
273
273
  AND = 1
274
274
  OR = 2
275
275
 
276
- def initialize(*conditions)
277
- if( [ AND, OR ].index(conditions.last) )
278
- @compoundType = conditions.last
279
- conditions.pop
276
+ def initialize( *args )
277
+ if( [ AND, OR ].index( args.last) )
278
+ @compoundType = args.last
279
+ args.pop
280
280
  else
281
281
  @compoundType = AND
282
282
  end
283
- @conditions = conditions
284
- @domain_class = conditions[0].domain_class
283
+ @conditions = args.map { |arg|
284
+ arg.respond_to?( :to_condition ) ? arg.to_condition : arg
285
+ }
286
+ @domain_class = @conditions[0].domain_class
285
287
  end
286
288
 
287
289
  def object_meets(anObj)
@@ -133,8 +133,12 @@ module Lafcadio
133
133
  consonantYPattern = Regexp.new("([^aeiou])y$", Regexp::IGNORECASE)
134
134
  if singular =~ consonantYPattern
135
135
  singular.gsub consonantYPattern, '\1ies'
136
+ elsif singular =~ /^(.*)xis$/
137
+ $1 + 'xes'
136
138
  elsif singular =~ /[xs]$/
137
139
  singular + "es"
140
+ elsif singular =~ /(.*)tum$/
141
+ $1 + 'ta'
138
142
  else
139
143
  singular + "s"
140
144
  end
@@ -1,4 +1,5 @@
1
1
  require 'delegate'
2
+ require 'lafcadio/depend'
2
3
  require 'singleton'
3
4
 
4
5
  module Lafcadio
@@ -66,14 +67,16 @@ module Lafcadio
66
67
  class ContextualService
67
68
  def self.flush; Context.instance.set_resource( self, nil ); end
68
69
 
69
- def self.method_missing( methodId, *args )
70
- methodName = methodId.id2name
71
- if methodName =~ /^get_(.*)/ || methodName =~ /^set_(.*)/
72
- if methodName =~ /^get_(.*)/
73
- Context.instance.get_resource( self )
74
- else
75
- Context.instance.set_resource( self, *args )
76
- end
70
+ def self.method_missing( symbol, *args )
71
+ method_name = symbol.id2name
72
+ target = nil
73
+ if method_name =~ /^get_(.*)/
74
+ target = :get_resource if $1.underscore_to_camel_case == basename
75
+ elsif method_name =~ /^set_(.*)/
76
+ target = :set_resource if $1.underscore_to_camel_case == basename
77
+ end
78
+ if target
79
+ Context.instance.send( target, self, *args )
77
80
  else
78
81
  super
79
82
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.8.1
2
+ rubygems_version: 0.8.6
3
3
  specification_version: 1
4
4
  name: lafcadio
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.6.4
7
- date: 2005-03-01
6
+ version: 0.6.5
7
+ date: 2005-07-17
8
8
  summary: Lafcadio is an object-relational mapping layer
9
9
  require_paths:
10
10
  - lib
11
- author: Francis Hwang
12
11
  email: sera@fhwang.net
13
12
  homepage: http://lafcadio.rubyforge.org/
14
13
  rubyforge_project:
@@ -29,6 +28,8 @@ required_ruby_version: !ruby/object:Gem::Version::Requirement
29
28
  version: 0.0.0
30
29
  version:
31
30
  platform: ruby
31
+ authors:
32
+ - Francis Hwang
32
33
  files:
33
34
  - lib/lafcadio
34
35
  - lib/lafcadio.rb