Class: Lafcadio::Query::Condition
- Inherits:
-
Object
- Object
- Lafcadio::Query::Condition
show all
- Defined in:
- lib/lafcadio/query/Condition.rb
Overview
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(fieldName, searchTerm, objectType) ⇒ Condition
Returns a new instance of Condition.
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/lafcadio/query/Condition.rb', line 12
def initialize(fieldName, searchTerm, objectType)
require 'lafcadio/domain/DomainObject'
@fieldName = fieldName
@searchTerm = searchTerm
unless @searchTerm.class <= self.class.searchTermType
raise "Incorrect searchTerm type #{ searchTerm.class }"
end
@objectType = objectType
if @objectType
unless @objectType <= DomainObject
raise "Incorrect object type #{ @objectType.to_s }"
end
end
end
|
Instance Attribute Details
#objectType ⇒ Object
Returns the value of attribute objectType.
10
11
12
|
# File 'lib/lafcadio/query/Condition.rb', line 10
def objectType
@objectType
end
|
Class Method Details
.searchTermType ⇒ Object
6
7
8
|
# File 'lib/lafcadio/query/Condition.rb', line 6
def Condition.searchTermType
Object
end
|
Instance Method Details
#dbFieldName ⇒ Object
32
33
34
35
36
37
38
39
40
|
# File 'lib/lafcadio/query/Condition.rb', line 32
def dbFieldName
if primaryKeyField?
db_table = @objectType.tableName
db_field_name = @objectType.sqlPrimaryKeyName
"#{ db_table }.#{ db_field_name }"
else
getField.db_table_and_field_name
end
end
|
#getField ⇒ Object
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/lafcadio/query/Condition.rb', line 42
def getField
anObjectType = @objectType
field = nil
while (anObjectType < DomainObject || anObjectType < DomainObject) &&
!field
field = anObjectType.getClassField( @fieldName ) ||
anObjectType.getClassFieldByDbFieldName( @fieldName )
anObjectType = anObjectType.superclass
end
if field
field
else
errStr = "Couldn't find field \"#{ @fieldName }\" in " +
"#{ @objectType } domain class"
raise( MissingError, errStr, caller )
end
end
|
#not ⇒ Object
60
61
62
63
|
# File 'lib/lafcadio/query/Condition.rb', line 60
def not
require 'lafcadio/query/Not'
Query::Not.new( self )
end
|
#primaryKeyField? ⇒ Boolean
28
29
30
|
# File 'lib/lafcadio/query/Condition.rb', line 28
def primaryKeyField?
[ @objectType.sqlPrimaryKeyName, 'pkId' ].include?( @fieldName )
end
|