Sha256: bdab41b73bebfd507205273a04e9f59e452e8100b526b13a91d78b6abf21b162
Contents?: true
Size: 1.23 KB
Versions: 1
Compression:
Stored size: 1.23 KB
Contents
module ActsAsBelongable module Belonger extend ActiveSupport::Concern module ClassMethods def acts_as_belonger has_many :belongables, through: :belonger_belongings, source: :belongable has_many :belonger_belongings, as: :belonger, class_name: 'Belonging', dependent: :destroy end def belonger name, source_type has_many name.to_sym, through: :belonger_belongings, source: :belongable, source_type: source_type.to_s end end def add_belongable belongable, options = {} options[:belongable] = belongable self.belonger_belongings.create options end def add_belongable! belongable, options = {} options[:belongable] = belongable self.belonger_belongings.create! options end def create_belongable class_name, options = {} object = class_name.constantize.create options self.add_belongable object end def create_belongable! class_name, options = {} object = class_name.constantize.create! options self.add_belongable! object end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
acts_as_belongable-1.0.0 | app/models/concerns/acts_as_belongable/belonger.rb |