Sha256: 3624364a3533757eefd782eaf9c866a183e8a8f54475f66d69512800d9a0bbef
Contents?: true
Size: 457 Bytes
Versions: 11
Compression:
Stored size: 457 Bytes
Contents
require 'active_record' class ActiveRecord::Base def self.object_id_attr(symbol, klass) module_eval %{ def #{symbol} if @#{symbol}.nil? or (@old_#{symbol}_id != #{symbol}_id) @old_#{symbol}_id = #{symbol}_id klass = #{klass}.descendants.find { |d| d.#{symbol}_name == #{symbol}_id } klass ||= #{klass} @#{symbol} = klass.new else @#{symbol} end end } end end
Version data entries
11 entries across 11 versions & 1 rubygems