Class: RussellEdge::HasManyPolymorphic::Engine

Inherits:
Rails::Engine
  • Object
show all
Defined in:
lib/has_many_polymorphic/engine.rb

Constant Summary collapse

DEFAULT_OPTIONS =
{:models => %w()}
@@options =
HashWithIndifferentAccess.new(DEFAULT_OPTIONS)

Class Method Summary collapse

Class Method Details

.add_models(models) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/has_many_polymorphic/engine.rb', line 23

def add_models(models)
  if models.is_a? Array
    @@options[:models] = @@options[:models] | models
  else
    @@options[:models] << models
  end
end

.autoload_modelsObject

Dispatcher callback to load polymorphic relationships



32
33
34
35
36
37
38
39
40
# File 'lib/has_many_polymorphic/engine.rb', line 32

def autoload_models
  @@options[:models].each do |model|
    #try to load model if it exists.
    begin
      model.constantize
    rescue=>e
    end
  end
end