Class: MoneyRails::Hooks

Inherits:
Object
  • Object
show all
Defined in:
lib/money-rails/hooks.rb

Class Method Summary collapse

Class Method Details

.initObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/money-rails/hooks.rb', line 3

def self.init
  # For Active Record
  ActiveSupport.on_load(:active_record) do
    require 'money-rails/active_model/validator'
    require 'money-rails/active_record/monetizable'
    ::ActiveRecord::Base.send :include, MoneyRails::ActiveRecord::Monetizable
  end

  # For Mongoid
  begin; require 'mongoid'; require 'mongoid/version'; rescue LoadError; end
  if defined? ::Mongoid
    if ::Mongoid::VERSION =~ /^2(.*)/
      require 'money-rails/mongoid/two' # Loading the file is enough
    end

    if ::Mongoid::VERSION =~ /^3(.*)/
      require 'money-rails/mongoid/three'
    end
  end

  # For ActionView
  ActiveSupport.on_load(:action_view) do
    require 'money-rails/helpers/action_view_extension'
    ::ActionView::Base.send :include, MoneyRails::ActionViewExtension
  end
end