Module: Army::Negative

Defined in:
lib/army-negative.rb,
lib/army-negative/column.rb,
lib/army-negative/quoting.rb,
lib/army-negative/railtie.rb,
lib/army-negative/version.rb,
lib/army-negative/mysql_adapter.rb

Defined Under Namespace

Modules: Column, MysqlAdapter, Quoting, Version Classes: Railtie

Class Method Summary collapse

Class Method Details

.activate!Object

Called during gem initialization (via Army::Negative::Railtie) in order to active army-negative and ensure all true values get stored as -1 and that -1’s are recognized as true.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/army-negative.rb', line 16

def activate!
  ActiveRecord::ConnectionAdapters::Column.send  :extend,  Column
  ActiveRecord::ConnectionAdapters::Quoting.send :include, Quoting
  # There may be one of two mysql adapters...
  adapter = 0
  begin
    adapter += 1
    require "active_record/connection_adapters/mysql#{adapter == 1 ? "" : adapter}_adapter"
  rescue LoadError => e
    retry unless adapter >= 2
    raise e
  end
  "ActiveRecord::ConnectionAdapters::Mysql#{adapter == 1 ? "" : adapter}Adapter".constantize.send :include, MysqlAdapter
end