Class: Lafcadio::Query::ObjectFieldImpostor
- Inherits:
-
Object
- Object
- Lafcadio::Query::ObjectFieldImpostor
show all
- Defined in:
- lib/lafcadio/query.rb
Overview
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(domainObjectImpostor, class_field_or_name) ⇒ ObjectFieldImpostor
Returns a new instance of ObjectFieldImpostor.
144
145
146
147
148
149
150
151
152
|
# File 'lib/lafcadio/query.rb', line 144
def initialize( domainObjectImpostor, class_field_or_name )
@domainObjectImpostor = domainObjectImpostor
if class_field_or_name == 'pkId'
@db_field_name = 'pkId'
else
@class_field = class_field_or_name
@db_field_name = class_field_or_name.dbFieldName
end
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(methId, *args) ⇒ Object
154
155
156
157
158
159
160
161
|
# File 'lib/lafcadio/query.rb', line 154
def method_missing( methId, *args )
methodName = methId.id2name
if !ObjectFieldImpostor.comparators.keys.index( methodName ).nil?
registerCompareCondition( methodName, *args )
else
super( methId, *args )
end
end
|
Instance Attribute Details
#class_field ⇒ Object
Returns the value of attribute class_field.
142
143
144
|
# File 'lib/lafcadio/query.rb', line 142
def class_field
@class_field
end
|
Instance Method Details
#equals(searchTerm) ⇒ Object
169
170
171
172
|
# File 'lib/lafcadio/query.rb', line 169
def equals( searchTerm )
Equals.new( @db_field_name, field_or_field_name( searchTerm ),
@domainObjectImpostor.domainClass )
end
|
#field_or_field_name(search_term) ⇒ Object
174
175
176
177
178
179
180
|
# File 'lib/lafcadio/query.rb', line 174
def field_or_field_name( search_term )
if search_term.class == ObjectFieldImpostor
search_term.class_field
else
search_term
end
end
|
#in(*searchTerms) ⇒ Object
197
198
199
200
|
# File 'lib/lafcadio/query.rb', line 197
def in( *searchTerms )
Query::In.new( @db_field_name, searchTerms,
@domainObjectImpostor.domainClass )
end
|
#like(regexp) ⇒ Object
182
183
184
185
186
187
188
189
190
191
192
193
194
195
|
# File 'lib/lafcadio/query.rb', line 182
def like( regexp )
if regexp.source =~ /^\^(.*)/
searchTerm = $1
matchType = Query::Like::POST_ONLY
elsif regexp.source =~ /(.*)\$$/
searchTerm = $1
matchType = Query::Like::PRE_ONLY
else
searchTerm = regexp.source
matchType = Query::Like::PRE_AND_POST
end
Query::Like.new( @db_field_name, searchTerm,
@domainObjectImpostor.domainClass, matchType )
end
|
#registerCompareCondition(compareStr, searchTerm) ⇒ Object
163
164
165
166
167
|
# File 'lib/lafcadio/query.rb', line 163
def registerCompareCondition( compareStr, searchTerm)
compareVal = ObjectFieldImpostor.comparators[compareStr]
Compare.new( @db_field_name, searchTerm,
@domainObjectImpostor.domainClass, compareVal )
end
|