class PowerEnum::Reflection::EnumerationReflection
Reflection
class for enum reflections. See ActiveRecord::Reflection
Constants
- EnumJoinKeys
Attributes
Public Class Methods
See ActiveRecord::Reflection::MacroReflection
# File lib/power_enum/reflection.rb, line 38 def initialize(name, options, active_record) super name, nil, options, active_record end
Public Instance Methods
# File lib/power_enum/reflection.rb, line 62 def active_record_primary_key @active_record_primary_key ||= options[:primary_key] || active_record.primary_key end
# File lib/power_enum/reflection.rb, line 72 def association_class ::ActiveRecord::Associations::HasOneAssociation end
Returns the primary key of the active record model that owns the has_enumerated association.
# File lib/power_enum/reflection.rb, line 101 def association_primary_key(klass = nil) active_record.primary_key end
Normally defined on AR::AssociationReflection::MacroReflection. Realistically, this is a belongs-to relationship.
# File lib/power_enum/reflection.rb, line 146 def belongs_to? true end
Returns an array of this instance as the only member.
# File lib/power_enum/reflection.rb, line 140 def chain [self] end
# File lib/power_enum/reflection.rb, line 46 def check_preloadable! return unless scope if scope.arity > 0 ActiveSupport::Deprecation.warn(<<-MSG.squish) The association scope '#{name}' is instance dependent (the scope block takes an argument). Preloading happens before the individual instances are created. This means that there is no instance being passed to the association scope. This will most likely result in broken or incorrect behavior. Joining, Preloading and eager loading of these associations is deprecated and will be removed in the future. MSG end end
Does nothing.
# File lib/power_enum/reflection.rb, line 106 def check_validity!; end
Returns the class name of the enum
# File lib/power_enum/reflection.rb, line 83 def class_name @class_name ||= (@options[:class_name] || @name).to_s.camelize end
Always returns true.
# File lib/power_enum/reflection.rb, line 124 def collection? true end
In this case, returns [[]]
# File lib/power_enum/reflection.rb, line 129 def conditions [[]] end
Returns the foreign key on the association owner’s table.
# File lib/power_enum/reflection.rb, line 88 def foreign_key @foreign_key ||= (@options[:foreign_key] || "#{@name}_id").to_s end
# File lib/power_enum/reflection.rb, line 78 def join_keys(*_) EnumJoinKeys.new(active_record_primary_key, foreign_key) end
# File lib/power_enum/reflection.rb, line 68 def klass @klass ||= active_record.send(:compute_type, class_name) end
# File lib/power_enum/reflection.rb, line 42 def macro :has_enumerated end
Always returns false. Necessary for stuff like Booking.where(:status => BookingStatus)
# File lib/power_enum/reflection.rb, line 119 def polymorphic? false end
An array of arrays of scopes. Each item in the outside array corresponds to a reflection in the chain
.
# File lib/power_enum/reflection.rb, line 152 def scope_chain scope ? [[scope]] : [[]] end
Returns :belongs_to. Kind of hackish, but otherwise AREL joins logic gets confused.
# File lib/power_enum/reflection.rb, line 135 def source_macro :belongs_to end
Returns nil
# File lib/power_enum/reflection.rb, line 109 def source_reflection; nil end
Returns the name of the enum table
# File lib/power_enum/reflection.rb, line 95 def table_name @table_name ||= self.class.const_get(class_name).table_name end
Returns nil
# File lib/power_enum/reflection.rb, line 114 def type nil end