Sha256: f515501b577bda9b347e2e5719da7dd06f32deff76b771e07dfcd2b00029d1cf

Contents?: true

Size: 901 Bytes

Versions: 7

Compression:

Stored size: 901 Bytes

Contents

module Coupler
  module Models
    class Matcher < Sequel::Model
      include CommonModel
      many_to_one :scenario
      one_to_many :comparisons

      plugin :nested_attributes
      nested_attributes :comparisons, :destroy => true

      def cross_match?
        comparisons.any? { |c| c.cross_match? }
      end

      private
        def validate
          super
          # use comparisons instead of comparisons_dataset, because the
          # comparisons aren't created yet
          result = comparisons.any? do |comparison|
            comparison.lhs_type == "field" && comparison.rhs_type == "field"
          end
          if !result
            errors.add(:base, "At least one field-to-field comparison is required.")
          end
        end

        def after_save
          super
          s = scenario
          s.set_linkage_type
          s.save
        end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
coupler-0.0.9-java lib/coupler/models/matcher.rb
coupler-0.0.8-java lib/coupler/models/matcher.rb
coupler-0.0.6-java lib/coupler/models/matcher.rb
coupler-0.0.4-java lib/coupler/models/matcher.rb
coupler-0.0.3-java lib/coupler/models/matcher.rb
coupler-0.0.2-java lib/coupler/models/matcher.rb
coupler-0.0.1-java lib/coupler/models/matcher.rb