Module: PowerEnum::Reflection::ClassMethods
- Defined in:
- lib/power_enum/reflection.rb
Overview
Class-level extensions injected into ActiveRecord
Class Method Summary collapse
-
.extended(base) ⇒ Object
:nodoc:.
Instance Method Summary collapse
-
#reflect_on_all_associations_with_enumeration(macro = nil) ⇒ Object
Extend associations with enumerations, preferring enumerations.
-
#reflect_on_all_enumerated ⇒ Object
All EnumerationReflection reflections.
-
#reflect_on_association_with_enumeration(associated) ⇒ Object
Extend associations with enumerations, preferring enumerations.
-
#reflect_on_enumerated(enumerated) ⇒ PowerEnum::Reflection::EnumerationReflection
If the reflection of the given name is an EnumerationReflection, returns the reflection, otherwise returns nil.
Class Method Details
.extended(base) ⇒ Object
:nodoc:
12 13 14 15 16 17 |
# File 'lib/power_enum/reflection.rb', line 12 def self.extended(base) # :nodoc: class << base alias_method_chain :reflect_on_all_associations, :enumeration alias_method_chain :reflect_on_association, :enumeration end end |
Instance Method Details
#reflect_on_all_associations_with_enumeration(macro = nil) ⇒ Object
Extend associations with enumerations, preferring enumerations
34 35 36 |
# File 'lib/power_enum/reflection.rb', line 34 def reflect_on_all_associations_with_enumeration(macro = nil) reflect_on_all_enumerated + reflect_on_all_associations_without_enumeration(macro) end |
#reflect_on_all_enumerated ⇒ Object
All EnumerationReflection reflections
20 21 22 23 24 |
# File 'lib/power_enum/reflection.rb', line 20 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_with_enumeration(associated) ⇒ Object
Extend associations with enumerations, preferring enumerations
39 40 41 |
# File 'lib/power_enum/reflection.rb', line 39 def reflect_on_association_with_enumeration( associated ) reflect_on_enumerated(associated) || reflect_on_association_without_enumeration(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.
29 30 31 |
# File 'lib/power_enum/reflection.rb', line 29 def reflect_on_enumerated( enumerated ) reflections[enumerated.to_sym].is_a?(PowerEnum::Reflection::EnumerationReflection) ? reflections[enumerated.to_sym] : nil end |