module PowerEnum::Reflection

Used to patch ActiveRecord reflections.

Public Instance Methods

reflect_on_all_associations(macro = nil) click to toggle source
Calls superclass method
# File lib/power_enum/reflection.rb, line 24
def reflect_on_all_associations(macro = nil)
  reflect_on_all_enumerated + super(macro)
end
reflect_on_all_enumerated() click to toggle source

All {PowerEnum::Reflection::EnumerationReflection} reflections

# File lib/power_enum/reflection.rb, line 10
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
reflect_on_association(associated) click to toggle source
Calls superclass method
# File lib/power_enum/reflection.rb, line 28
def reflect_on_association(associated)
  reflect_on_enumerated(associated) || super(associated)
end
reflect_on_enumerated( enumerated ) click to toggle source

If the reflection of the given name is an EnumerationReflection, returns the reflection, otherwise returns nil. @return [PowerEnum::Reflection::EnumerationReflection]

# File lib/power_enum/reflection.rb, line 19
def reflect_on_enumerated( enumerated )
  key = enumerated.to_s
  reflections[key].is_a?(PowerEnum::Reflection::EnumerationReflection) ? reflections[key] : nil
end