Class: Lafcadio::Query::CompoundCondition
Overview
Instance Attribute Summary
Attributes inherited from Condition
#domain_class
Instance Method Summary
collapse
Methods inherited from Condition
#&, #db_field_name, #eql?, #field, #not, #one_pk_id?, #primary_key_field?, #query, search_term_type, #to_condition, #|
Constructor Details
Returns a new instance of CompoundCondition.
444
445
446
447
448
449
450
451
452
453
454
455
|
# File 'lib/lafcadio/query.rb', line 444
def initialize( *args )
if( [ :and, :or ].include?( args.last ) )
@compound_type = args.last
args.pop
else
@compound_type = :and
end
@conditions = args.map { |arg|
arg.respond_to?( :to_condition ) ? arg.to_condition : arg
}
@domain_class = @conditions[0].domain_class
end
|
Instance Method Details
#dobj_satisfies?(anObj) ⇒ Boolean
457
458
459
460
461
462
463
464
465
466
467
|
# File 'lib/lafcadio/query.rb', line 457
def dobj_satisfies?(anObj)
if @compound_type == :and
@conditions.inject( true ) { |result, cond|
result && cond.dobj_satisfies?( anObj )
}
else
@conditions.inject( false ) { |result, cond|
result || cond.dobj_satisfies?( anObj )
}
end
end
|
#implied_by?(other_condition) ⇒ Boolean
469
470
471
472
473
|
# File 'lib/lafcadio/query.rb', line 469
def implied_by?( other_condition )
@compound_type == :or && @conditions.any? { |cond|
cond.implies?( other_condition )
}
end
|
#implies?(other_condition) ⇒ Boolean
475
476
477
478
479
480
481
482
483
484
485
|
# File 'lib/lafcadio/query.rb', line 475
def implies?( other_condition )
super( other_condition ) or (
@compound_type == :and and @conditions.any? { |cond|
cond.implies? other_condition
}
) or (
@compound_type == :or and @conditions.all? { |cond|
cond.implies? other_condition
}
)
end
|
#to_sql ⇒ Object
487
488
489
490
491
|
# File 'lib/lafcadio/query.rb', line 487
def to_sql
booleanString = @compound_type == :and ? 'and' : 'or'
subSqlStrings = @conditions.collect { |cond| cond.to_sql }
"(#{ subSqlStrings.join(" #{ booleanString } ") })"
end
|