Sha256: ae4feb446bf648b7af442189f56dca28bd6117e97844d7ea39d0bbc7759d5f8a
Contents?: true
Size: 1.01 KB
Versions: 18
Compression:
Stored size: 1.01 KB
Contents
# Copyright (c) 2011 Artem Kuzko # Released under the MIT license. See LICENSE for details. module PowerEnum::Reflection extend ActiveSupport::Concern module ClassMethods def reflect_on_all_enumerated # Need to give it a full namespace to avoid getting Rails confused in development # mode where all objects are reloaded on every request. reflections.values.grep(PowerEnum::Reflection::EnumerationReflection) end def reflect_on_enumerated( enumerated ) reflections[enumerated.to_sym].is_a?(PowerEnum::Reflection::EnumerationReflection) ? reflections[enumerated.to_sym] : nil end end class EnumerationReflection < ActiveRecord::Reflection::MacroReflection def initialize( name, options, active_record ) super :has_enumerated, name, options, active_record end def class_name @class_name ||= (@options[:class_name] || @name).to_s.camelize end def foreign_key @foreign_key ||= (@options[:foreign_key] || "#{@name}_id").to_s end end end
Version data entries
18 entries across 18 versions & 1 rubygems