Sha256: a2a0f84cf06c50ac086c4ecf3989439b0d4b69f444d5d724e4e9db3f760cecc1

Contents?: true

Size: 1.34 KB

Versions: 8

Compression:

Stored size: 1.34 KB

Contents

module MoneyRails
  class Hooks
    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

        %w{options_extractor schema_statements table}.each { |file| require "money-rails/active_record/migration_extensions/#{file}" }
        ::ActiveRecord::Migration.send :include, MoneyRails::ActiveRecord::MigrationExtensions::SchemaStatements
        ::ActiveRecord::ConnectionAdapters::TableDefinition.send :include, MoneyRails::ActiveRecord::MigrationExtensions::Table
        ::ActiveRecord::ConnectionAdapters::Table.send :include, MoneyRails::ActiveRecord::MigrationExtensions::Table
      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
        else
          require 'money-rails/mongoid/money'
        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
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
money-rails-1.2.0 lib/money-rails/hooks.rb
money-rails-1.1.0 lib/money-rails/hooks.rb
money-rails-1.0.0 lib/money-rails/hooks.rb
money-rails-0.12.0 lib/money-rails/hooks.rb
money-rails-0.11.0 lib/money-rails/hooks.rb
money-rails-0.10.0 lib/money-rails/hooks.rb
money-rails-0.9.0 lib/money-rails/hooks.rb
money-rails-0.8.1 lib/money-rails/hooks.rb