Module: Shared::OriginRelationship::ClassMethods
- Defined in:
- app/models/concerns/shared/origin_relationship.rb
Instance Method Summary collapse
Instance Method Details
#is_origin_for(*args) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'app/models/concerns/shared/origin_relationship.rb', line 44 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 |
#originates_from(*args) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'app/models/concerns/shared/origin_relationship.rb', line 67 def originates_from(*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_old_object_classes do args end # @return [Array of Strings] # valid new_object Classes define_singleton_method :valid_old_object_classes do args end args.each do |a| relationship = 'origin_' + a.demodulize.tableize has_many relationship.to_sym, source_type: a, through: :related_origin_relationships, source: :old_object end end |