Module: Shared::OriginRelationship::ClassMethods

Defined in:
app/models/concerns/shared/origin_relationship.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) is_origin_for(*args)



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'app/models/concerns/shared/origin_relationship.rb', line 38

def is_origin_for(*args)
  if args.length == 0
    raise ArgumentError.new("is_origin_for must have an array full of valid target tables supplied!")
  end

  # @return [Array of Strings]
  #   valid new_object Classes
  define_method :valid_new_object_classes do
    args
  end

  # @return [Array of Strings]
  #   valid new_object Classes
  define_singleton_method :valid_new_object_classes do
    args
  end

  args.each do |a|
    relationship = 'derived_' + a.demodulize.tableize 
    has_many relationship.to_sym, source_type: a, through: :origin_relationships, source: :new_object 
  end
end