Module: Concerns::Model::BaseThing::ClassMethods

Defined in:
lib/concerns/model/base_thing.rb

Instance Method Summary collapse

Instance Method Details

#listObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/concerns/model/base_thing.rb', line 25

def list
  #if self.to_s.constantize.const_defined?('LIST_ID') && LIST_ID.present?
  #  self.to_s.constantize.list_instance ||= List.find(LIST_ID)
  #end
  
  return self.to_s.constantize.list_instance if self.to_s.constantize.list_instance.present?
  
  attributes = {
    adjective: 'best', topic: self.to_s, scope: 'ever', thing_type: self.to_s,
    negative_adjective: 'worst'
  }
  
  self.to_s.constantize.list_instance = List.where(attributes).first
  
  unless self.to_s.constantize.list_instance.present?
    self.to_s.constantize.list_instance = List.create!(attributes)      
  end
  
  self.to_s.constantize.list_instance
end