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

Version Path
radiant-0.6.1 lib/plugins/active_record_extensions/lib/active_record_extensions.rb
radiant-0.6.0 lib/plugins/active_record_extensions/lib/active_record_extensions.rb
radiant-0.6.3 lib/plugins/active_record_extensions/lib/active_record_extensions.rb
radiant-0.6.2 lib/plugins/active_record_extensions/lib/active_record_extensions.rb
radiant-0.6.4 lib/plugins/active_record_extensions/lib/active_record_extensions.rb
radiant-0.6.5.1 lib/plugins/active_record_extensions/lib/active_record_extensions.rb
radiant-0.6.5 lib/plugins/active_record_extensions/lib/active_record_extensions.rb
radiant-0.6.6 lib/plugins/active_record_extensions/lib/active_record_extensions.rb
radiant-0.6.7 lib/plugins/active_record_extensions/lib/active_record_extensions.rb
radiant-0.6.8 lib/plugins/active_record_extensions/lib/active_record_extensions.rb
radiant-0.6.9 lib/plugins/active_record_extensions/lib/active_record_extensions.rb