Class: OriginRelationship

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Housekeeping
Defined in:
app/models/origin_relationship.rb

Instance Method Summary (collapse)

Methods included from Housekeeping

#has_polymorphic_relationship?

Instance Method Details

- (Object) valid_source_target_pairs



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/models/origin_relationship.rb', line 36

def valid_source_target_pairs
  if old_object_type.nil? || new_object_type.nil?
    errors.add(:source, "can't be nil!") if old_object_type.nil?
    errors.add(:target, "can't be nil!") if new_object_type.nil?
    return
  end

  old_object_type_class = old_object_type.constantize

  if !old_object_type_class.respond_to?(:valid_origin_target_classes)
    errors.add(:source, "#{old_object_type} is not a valid origin relationship source!")
  elsif !old_object_type_class.valid_origin_target_classes.include?(new_object_type.constantize)
    errors.add(:target, "#{new_object_type} is not a valid origin relationship target for source #{old_object_type}")
  end
end