Class: PowerEnum::Reflection::EnumerationReflection
- Inherits:
-
ActiveRecord::Reflection::MacroReflection
- Object
- ActiveRecord::Reflection::MacroReflection
- PowerEnum::Reflection::EnumerationReflection
- Defined in:
- lib/power_enum/reflection.rb
Overview
Reflection class for enum reflections. See ActiveRecord::Reflection
Defined Under Namespace
Classes: EnumJoinKeys
Instance Attribute Summary collapse
-
#counter_cache_column ⇒ Object
readonly
Returns the value of attribute counter_cache_column.
-
#parent_reflection ⇒ Object
Returns the value of attribute parent_reflection.
Instance Method Summary collapse
- #active_record_primary_key ⇒ Object (also: #join_primary_key)
- #association_class ⇒ Object
-
#association_primary_key(klass = nil) ⇒ Object
Returns the primary key of the active record model that owns the has_enumerated association.
-
#belongs_to? ⇒ Boolean
Normally defined on AR::AssociationReflection::MacroReflection.
-
#chain ⇒ Object
Returns an array of this instance as the only member.
- #check_preloadable! ⇒ Object (also: #check_eager_loadable!)
-
#check_validity! ⇒ Object
Does nothing.
-
#class_name ⇒ Object
Returns the class name of the enum.
-
#collection? ⇒ Boolean
Always returns true.
-
#conditions ⇒ Object
In this case, returns [[]].
- #deprecated? ⇒ Boolean
-
#foreign_key ⇒ Object
(also: #join_foreign_key)
Returns the foreign key on the association owner's table.
-
#initialize(name, options, active_record) ⇒ EnumerationReflection
constructor
See ActiveRecord::Reflection::MacroReflection.
- #join_keys(*_) ⇒ Object
- #klass ⇒ Object
- #macro ⇒ Object
-
#polymorphic? ⇒ Boolean
Always returns false.
-
#scope_chain ⇒ Object
An array of arrays of scopes.
-
#source_macro ⇒ Object
Returns :belongs_to.
-
#source_reflection ⇒ Object
Returns nil.
-
#table_name ⇒ Object
Returns the name of the enum table.
-
#type ⇒ Object
(also: #join_primary_type)
Returns nil.
Constructor Details
#initialize(name, options, active_record) ⇒ EnumerationReflection
See ActiveRecord::Reflection::MacroReflection
40 41 42 |
# File 'lib/power_enum/reflection.rb', line 40 def initialize(name, , active_record) super name, nil, , active_record end |
Instance Attribute Details
#counter_cache_column ⇒ Object (readonly)
Returns the value of attribute counter_cache_column.
36 37 38 |
# File 'lib/power_enum/reflection.rb', line 36 def counter_cache_column @counter_cache_column end |
#parent_reflection ⇒ Object
Returns the value of attribute parent_reflection.
37 38 39 |
# File 'lib/power_enum/reflection.rb', line 37 def parent_reflection @parent_reflection end |
Instance Method Details
#active_record_primary_key ⇒ Object Also known as: join_primary_key
64 65 66 |
# File 'lib/power_enum/reflection.rb', line 64 def active_record_primary_key @active_record_primary_key ||= [:primary_key] || active_record.primary_key end |
#association_class ⇒ Object
74 75 76 |
# File 'lib/power_enum/reflection.rb', line 74 def association_class ::ActiveRecord::Associations::HasOneAssociation end |
#association_primary_key(klass = nil) ⇒ Object
Returns the primary key of the active record model that owns the has_enumerated association.
103 104 105 |
# File 'lib/power_enum/reflection.rb', line 103 def association_primary_key(klass = nil) active_record.primary_key end |
#belongs_to? ⇒ Boolean
Normally defined on AR::AssociationReflection::MacroReflection. Realistically, this is a belongs-to relationship.
156 157 158 |
# File 'lib/power_enum/reflection.rb', line 156 def belongs_to? true end |
#chain ⇒ Object
Returns an array of this instance as the only member.
150 151 152 |
# File 'lib/power_enum/reflection.rb', line 150 def chain [self] end |
#check_preloadable! ⇒ Object Also known as: check_eager_loadable!
48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/power_enum/reflection.rb', line 48 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 |
#check_validity! ⇒ Object
Does nothing.
108 |
# File 'lib/power_enum/reflection.rb', line 108 def check_validity!; end |
#class_name ⇒ Object
Returns the class name of the enum
85 86 87 |
# File 'lib/power_enum/reflection.rb', line 85 def class_name @class_name ||= (@options[:class_name] || @name).to_s.camelize end |
#collection? ⇒ Boolean
Always returns true.
129 130 131 |
# File 'lib/power_enum/reflection.rb', line 129 def collection? true end |
#conditions ⇒ Object
In this case, returns [[]]
139 140 141 |
# File 'lib/power_enum/reflection.rb', line 139 def conditions [[]] end |
#deprecated? ⇒ Boolean
134 135 136 |
# File 'lib/power_enum/reflection.rb', line 134 def deprecated? false end |
#foreign_key ⇒ Object Also known as: join_foreign_key
Returns the foreign key on the association owner's table.
90 91 92 |
# File 'lib/power_enum/reflection.rb', line 90 def foreign_key @foreign_key ||= (@options[:foreign_key] || "#{@name}_id").to_s end |
#join_keys(*_) ⇒ Object
80 81 82 |
# File 'lib/power_enum/reflection.rb', line 80 def join_keys(*_) EnumJoinKeys.new(active_record_primary_key, foreign_key) end |
#klass ⇒ Object
70 71 72 |
# File 'lib/power_enum/reflection.rb', line 70 def klass @klass ||= active_record.send(:compute_type, class_name) end |
#macro ⇒ Object
44 45 46 |
# File 'lib/power_enum/reflection.rb', line 44 def macro :has_enumerated end |
#polymorphic? ⇒ Boolean
Always returns false. Necessary for stuff like Booking.where(:status => BookingStatus)
124 125 126 |
# File 'lib/power_enum/reflection.rb', line 124 def polymorphic? false end |
#scope_chain ⇒ Object
An array of arrays of scopes. Each item in the outside array corresponds to a reflection in the #chain.
162 163 164 |
# File 'lib/power_enum/reflection.rb', line 162 def scope_chain scope ? [[scope]] : [[]] end |
#source_macro ⇒ Object
Returns :belongs_to. Kind of hackish, but otherwise AREL joins logic gets confused.
145 146 147 |
# File 'lib/power_enum/reflection.rb', line 145 def source_macro :belongs_to end |
#source_reflection ⇒ Object
Returns nil
111 112 113 |
# File 'lib/power_enum/reflection.rb', line 111 def source_reflection nil end |
#table_name ⇒ Object
Returns the name of the enum table
97 98 99 |
# File 'lib/power_enum/reflection.rb', line 97 def table_name @table_name ||= self.class.const_get(class_name).table_name end |
#type ⇒ Object Also known as: join_primary_type
Returns nil
116 117 118 |
# File 'lib/power_enum/reflection.rb', line 116 def type nil end |