Module: PowerEnum::Reflection
- Defined in:
- lib/power_enum/reflection.rb
Overview
Used to patch ActiveRecord reflections.
Defined Under Namespace
Classes: EnumerationReflection
Instance Method Summary collapse
- #reflect_on_all_associations(macro = nil) ⇒ Object
-
#reflect_on_all_enumerated ⇒ Object
All EnumerationReflection reflections.
- #reflect_on_association(associated) ⇒ Object
-
#reflect_on_enumerated(enumerated) ⇒ PowerEnum::Reflection::EnumerationReflection
If the reflection of the given name is an EnumerationReflection, returns the reflection, otherwise returns nil.
Instance Method Details
#reflect_on_all_associations(macro = nil) ⇒ Object
26 27 28 |
# File 'lib/power_enum/reflection.rb', line 26 def reflect_on_all_associations(macro = nil) reflect_on_all_enumerated + super(macro) end |
#reflect_on_all_enumerated ⇒ Object
All EnumerationReflection reflections
12 13 14 15 16 |
# File 'lib/power_enum/reflection.rb', line 12 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) ⇒ Object
30 31 32 |
# File 'lib/power_enum/reflection.rb', line 30 def reflect_on_association(associated) reflect_on_enumerated(associated) || super(associated) end |
#reflect_on_enumerated(enumerated) ⇒ PowerEnum::Reflection::EnumerationReflection
If the reflection of the given name is an EnumerationReflection, returns the reflection, otherwise returns nil.
21 22 23 24 |
# File 'lib/power_enum/reflection.rb', line 21 def reflect_on_enumerated( enumerated ) key = enumerated.to_s reflections[key].is_a?(PowerEnum::Reflection::EnumerationReflection) ? reflections[key] : nil end |