Class: ActiveFacts::CQL::Compiler::Query
- Inherits:
-
ObjectType
- Object
- Definition
- ObjectType
- ActiveFacts::CQL::Compiler::Query
- Defined in:
- lib/activefacts/cql/compiler/fact_type.rb
Overview
A fact type which is objectified (whether derived or not) is also an ObjectType
Direct Known Subclasses
Instance Attribute Summary collapse
-
#conditions ⇒ Object
readonly
Returns the value of attribute conditions.
-
#context ⇒ Object
readonly
Exposed for testing purposes.
Attributes inherited from ObjectType
Attributes inherited from Definition
#constellation, #tree, #vocabulary
Instance Method Summary collapse
- #compile ⇒ Object
- #detect_projection_by_equality(condition) ⇒ Object
-
#initialize(name, conditions = nil, returning = nil) ⇒ Query
constructor
A new instance of Query.
- #is_projected_role(rr) ⇒ Object
- #match_condition_fact_types ⇒ Object
- #prepare_roles(clauses = nil) ⇒ Object
Methods inherited from ObjectType
Methods inherited from Definition
#all_bindings_in_clauses, #build_all_steps, #build_steps, #build_variables, #source, #to_s
Constructor Details
#initialize(name, conditions = nil, returning = nil) ⇒ Query
Returns a new instance of Query.
9 10 11 12 13 |
# File 'lib/activefacts/cql/compiler/fact_type.rb', line 9 def initialize name, conditions = nil, returning = nil super name @conditions = conditions @returning = returning || [] end |
Instance Attribute Details
#conditions ⇒ Object (readonly)
Returns the value of attribute conditions.
7 8 9 |
# File 'lib/activefacts/cql/compiler/fact_type.rb', line 7 def conditions @conditions end |
#context ⇒ Object (readonly)
Exposed for testing purposes
6 7 8 |
# File 'lib/activefacts/cql/compiler/fact_type.rb', line 6 def context @context end |
Instance Method Details
#compile ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/activefacts/cql/compiler/fact_type.rb', line 22 def compile # Match roles with players, and match clauses with existing fact types prepare_roles unless @context @context.left_contraction_allowed = true match_condition_fact_types # Build the query: unless @conditions.empty? and !@returning debug :query, "building query for derived fact type" do @query = build_variables(@conditions.flatten) @roles_by_binding = build_all_steps(@conditions) @query.validate @query end end @context.left_contraction_allowed = false @query end |
#detect_projection_by_equality(condition) ⇒ Object
53 54 55 56 57 58 59 60 |
# File 'lib/activefacts/cql/compiler/fact_type.rb', line 53 def detect_projection_by_equality condition return false unless condition.is_a?(Comparison) if is_projected_role(condition.e1) condition.project :left elsif is_projected_role(condition.e2) condition.project :right end end |
#is_projected_role(rr) ⇒ Object
62 63 64 |
# File 'lib/activefacts/cql/compiler/fact_type.rb', line 62 def is_projected_role(rr) false end |
#match_condition_fact_types ⇒ Object
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/activefacts/cql/compiler/fact_type.rb', line 42 def match_condition_fact_types @conditions.each do |condition| next if condition.is_naked_object_type # REVISIT: Many conditions will imply a number of different steps, which need to be handled (similar to nested_clauses). debug :projection, "matching condition fact_type #{condition.inspect}" do fact_type = condition.match_existing_fact_type @context raise "Unrecognised fact type #{condition.inspect} in #{self.class}" unless fact_type end end end |
#prepare_roles(clauses = nil) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/activefacts/cql/compiler/fact_type.rb', line 15 def prepare_roles clauses = nil debug :binding, "preparing roles" do @context ||= CompilationContext.new(@vocabulary) @context.bind clauses||[], @conditions, @returning end end |