class PowerEnum::Reflection::EnumerationReflection

Reflection class for enum reflections. See ActiveRecord::Reflection

Constants

EnumJoinKeys

Attributes

counter_cache_column[R]
parent_reflection[RW]

Public Class Methods

new(name, options, active_record) click to toggle source

See ActiveRecord::Reflection::MacroReflection

Calls superclass method
# File lib/power_enum/reflection.rb, line 38
def initialize(name, options, active_record)
  super name, nil, options, active_record
end

Public Instance Methods

active_record_primary_key() click to toggle source
# 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
Also aliased as: join_primary_key
association_class() click to toggle source
# File lib/power_enum/reflection.rb, line 72
def association_class
  ::ActiveRecord::Associations::HasOneAssociation
end
association_primary_key(klass = nil) click to toggle source

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
belongs_to?() click to toggle source

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
chain() click to toggle source

Returns an array of this instance as the only member.

# File lib/power_enum/reflection.rb, line 140
def chain
  [self]
end
check_eager_loadable!()
Alias for: check_preloadable!
check_preloadable!() click to toggle source
# 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
Also aliased as: check_eager_loadable!
check_validity!() click to toggle source

Does nothing.

# File lib/power_enum/reflection.rb, line 106
def check_validity!; end
class_name() click to toggle source

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
collection?() click to toggle source

Always returns true.

# File lib/power_enum/reflection.rb, line 124
def collection?
  true
end
conditions() click to toggle source

In this case, returns [[]]

# File lib/power_enum/reflection.rb, line 129
def conditions
  [[]]
end
foreign_key() click to toggle source

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
Also aliased as: join_foreign_key
join_foreign_key()
Alias for: foreign_key
join_keys(*_) click to toggle source
# File lib/power_enum/reflection.rb, line 78
def join_keys(*_)
  EnumJoinKeys.new(active_record_primary_key, foreign_key)
end
join_primary_key()
klass() click to toggle source
# File lib/power_enum/reflection.rb, line 68
def klass
  @klass ||= active_record.send(:compute_type, class_name)
end
macro() click to toggle source
# File lib/power_enum/reflection.rb, line 42
def macro
  :has_enumerated
end
polymorphic?() click to toggle source

Always returns false. Necessary for stuff like Booking.where(:status => BookingStatus)

# File lib/power_enum/reflection.rb, line 119
def polymorphic?
  false
end
scope_chain() click to toggle source

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
source_macro() click to toggle source

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
source_reflection() click to toggle source

Returns nil

# File lib/power_enum/reflection.rb, line 109
def source_reflection;
  nil
end
table_name() click to toggle source

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
type() click to toggle source

Returns nil

# File lib/power_enum/reflection.rb, line 114
def type
  nil
end