module Cookbook::Mixins::ActsAsUseOf::ClassMethods

Extended by has_cookbook mixin

Attributes

used_in[RW]

Public Instance Methods

associate_used_in() click to toggle source
# File lib/cookbook/mixins/acts_as_use_of.rb, line 24
def associate_used_in
  used_in.each do |table_sym|
    model = table_sym.to_s.classify.constantize
    name = model.model_name.to_s
    uses_symbol = "#{model.model_name.param_key}_uses".to_sym

    has_many uses_symbol, lambda {
      where(use_of_type: name)
    }, as: :use_in, class_name: 'Cookbook::Use'
    accepts_nested_attributes_for uses_symbol, reject_if: :all_blank, allow_destroy: true

    has_many table_sym, through: :uses, source: :use_of, source_type: name
  end
end