Class: ActiveHash::Reflection::BelongsToReflection

Inherits:
ActiveRecord::Reflection::BelongsToReflection
  • Object
show all
Defined in:
lib/associations/reflection_extensions.rb

Instance Method Summary collapse

Instance Method Details

#compute_class(name) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/associations/reflection_extensions.rb', line 4

def compute_class(name)
  if polymorphic?
    raise ArgumentError, "Polymorphic associations do not support computing the class."
  end
  
  begin
    klass = active_record.send(:compute_type, name)
  rescue NameError => error
    if error.name.match?(/(?:\A|::)#{name}\z/)
      message = "Missing model class #{name} for the #{active_record}##{self.name} association."
      message += " You can specify a different model class with the :class_name option." unless options[:class_name]
      raise NameError.new(message, name)
    else
      raise
    end
  end

  klass
end