Module: ActiveRecordInclude::WhenConnected::OnConnect::ClassMethods

Defined in:
lib/active_record_include/when_connected.rb

Instance Method Summary collapse

Instance Method Details

#connectionObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/active_record_include/when_connected.rb', line 30

def connection(*)
  super.tap do
    self.modules_to_include_when_connected.each do |config|
    config.each do |(mod, options)|
      self.singleton_class.class_eval do
        attr_accessor :modules_already_included_when_connected
      end
      self.modules_already_included_when_connected ||= []
      next if self.modules_already_included_when_connected.include?(mod)

      match = (
        if options[:into_classes]
          self.in? options[:into_classes]
        else
          self < ActiveRecord::Base && !self.abstract_class?
        end
      )
      #puts %(Include #{mod} into #{self} (#{options.inspect})? #{match})
      if match
        puts "Including #{mod} into #{self}" if ActiveRecordInclude::WhenConnected.verbose
        modules_already_included_when_connected << mod
        class_eval do
          include mod
        end
      end
    end
    end
  end
end