lib/activefacts/cql/compiler/constraint.rb in activefacts-cql-1.8.1 vs lib/activefacts/cql/compiler/constraint.rb in activefacts-cql-1.8.2

- old
+ new

@@ -12,23 +12,23 @@ constellation.Enforcement(constraint, :enforcement_code => @action, :agent => @agent) end end class ContextNote - attr_reader :context_kind, :discussion, :who, :agreed_date, :agreed_agents + attr_reader :context_kind, :description, :who, :agreed_date, :agreed_agents - def initialize context_kind, discussion, who, agreed - @context_kind, @discussion, @who, @agreed = context_kind, discussion, who, agreed + def initialize context_kind, description, who, agreed + @context_kind, @description, @who, @agreed = context_kind, description, who, agreed @agreed_date, @agreed_agents = *agreed end def compile constellation, target context_note = constellation.ContextNote( :new, :context_note_kind => @context_kind, - :discussion => @discussion + :description => @description ) context_note.relevant_concept = target.concept if @agreed_date || @agreed_agents agreement = constellation.Agreement(context_note) agreement.date = @agreed_date if @agreed_date @@ -47,18 +47,18 @@ class Constraint < Definition def initialize context_note, enforcement, clauses_lists = [] if context_note.is_a?(Treetop::Runtime::SyntaxNode) && !context_note.empty? context_note = context_note.empty? ? nil : context_note.ast - else - context_note = nil # Perhaps a context note got attached to one of the clauses. Steal it. - clauses_lists.detect do |clauses_list| - if c = clauses_list.last.context_note - context_note = c - clauses_list.last.context_note = nil - end - end + else + context_note = nil # Perhaps a context note got attached to one of the clauses. Steal it. + clauses_lists.detect do |clauses_list| + if c = clauses_list.last.context_note + context_note = c + clauses_list.last.context_note = nil + end + end end @context_note = context_note @enforcement = enforcement @clauses_lists = clauses_lists end @@ -231,17 +231,17 @@ :min_frequency => @quantifier.min, :max_frequency => @quantifier.max, :is_preferred_identifier => false, :is_mandatory => @quantifier.min && @quantifier.min > 0 ) - if @quantifier.pragmas - @quantifier.pragmas.each do |p| - @constellation.ConceptAnnotation(:concept => @constraint.concept, :mapping_annotation => p) - end - end + if @quantifier.pragmas + @quantifier.pragmas.each do |p| + @constellation.ConceptAnnotation(:concept => @constraint.concept, :mapping_annotation => p) + end + end @enforcement.compile(@constellation, @constraint) if @enforcement - trace :constraint, "Made new PC GUID=#{@constraint.concept.guid} min=#{@quantifier.min.inspect} max=#{@quantifier.max.inspect} over #{role_sequence.describe}" + trace :constraint, "Made new PC GUID=#{@constraint.concept.guid} min=#{@quantifier.min.inspect} max=#{@quantifier.max.inspect} over #{role_sequence.describe}" super end # In a PresenceConstraint, each role in "each XYZ" must occur in exactly one clauses_list def loose_binding @@ -283,13 +283,13 @@ zip(@bindings_by_list). map do |clauses_list, bindings| # Does this clauses_list involve a query? if clauses_list.size > 1 or clauses_list.detect do |clause| - clause.refs.detect{|ref| ref.nested_clauses } or - clause.includes_literals - end + clause.refs.detect{|ref| ref.nested_clauses } or + clause.includes_literals + end trace :query, "Building query for #{clauses_list.inspect}" do trace :query, "Constrained bindings are #{@common_bindings.inspect}" # Every Binding in these clauses becomes a Variable, # and every clause becomes a Step (and a RoleSequence). @@ -388,15 +388,15 @@ @constraint = @constellation.SetExclusionConstraint( :new, :vocabulary => @vocabulary, :is_mandatory => @quantifier.min == 1 ) - if @quantifier.pragmas - @quantifier.pragmas.each do |p| - @constellation.ConceptAnnotation(:concept => @constraint.concept, :mapping_annotation => p) - end - end + if @quantifier.pragmas + @quantifier.pragmas.each do |p| + @constellation.ConceptAnnotation(:concept => @constraint.concept, :mapping_annotation => p) + end + end @enforcement.compile(@constellation, @constraint) if @enforcement role_sequences.each_with_index do |role_sequence, i| @constellation.SetComparisonRoles(@constraint, i, :role_sequence => role_sequence) end super @@ -516,39 +516,39 @@ @value_ranges = ast[:ranges] @units = ast[:units] @regular_expression = ast[:regular_expression] end - def assert_value(val) - if val.is_a?(String) - @constellation.Value(eval(val), true, nil) - elsif val - @constellation.Value(val.to_s, false , nil) - else - nil - end - end + def assert_value(val) + if val.is_a?(String) + @constellation.Value(eval(val), true, nil) + elsif val + @constellation.Value(val.to_s, false , nil) + else + nil + end + end def compile @constraint = @constellation.ValueConstraint(:new) raise "Units on value constraints are not yet processed (at line #{'REVISIT'})" if @units # @string.line_of(node.interval.first) - if @value_ranges - @value_ranges.each do |range| - min, max = Array === range ? range : [range, range] - v_range = @constellation.ValueRange( - min && @constellation.Bound(:value => assert_value(min), :is_inclusive => true), - max && @constellation.Bound(:value => assert_value(max), :is_inclusive => true)) - ar = @constellation.AllowedRange(@constraint, v_range) - end - else - @constraint.regular_expression = @regular_expression - end - @enforcement.compile(@constellation, @constraint) if @enforcement - super - end + if @value_ranges + @value_ranges.each do |range| + min, max = Array === range ? range : [range, range] + v_range = @constellation.ValueRange( + min && @constellation.Bound(:value => assert_value(min), :is_inclusive => true), + max && @constellation.Bound(:value => assert_value(max), :is_inclusive => true)) + ar = @constellation.AllowedRange(@constraint, v_range) + end + else + @constraint.regular_expression = @regular_expression + end + @enforcement.compile(@constellation, @constraint) if @enforcement + super + end def vrto_s vr if Array === vr min = vr[0] max = vr[1] @@ -566,13 +566,13 @@ end end def to_s "#{super} to " + - (@value_ranges ? - "(#{@value_ranges.map{|vr| vrto_s(vr) }.inspect })#{ @units ? " in #{@units.inspect}" : ''}" : - @regular_expression - ) + (@value_ranges ? + "(#{@value_ranges.map{|vr| vrto_s(vr) }.inspect })#{ @units ? " in #{@units.inspect}" : ''}" : + @regular_expression + ) end end end end