
# Asset groups
if (Rails.groups.map(&:to_s) & %w[development assets test]).any?
  require "font-awesome-rails"
  require "sass-rails"
  require "js-routes"
  require "momentjs-rails"
  require 'coffee-rails'
  require "pickadate-rails"
end

require "slim-rails"
require 'record_collection'
require 'request_store'
require 'ransack'
require 'devise'
require 'devise-token_authenticatable'
require 'state_machines-activerecord'
require 'carrierwave'
require 'simple_form'
require 'redcarpet'
require 'exception_notification'
require 'facets/enumerable/map_send'
require 'memoist'
require 'cancancan'

if Rails::VERSION::MAJOR < 5
  ActiveRecord::Associations::Builder::Association.valid_options |= [:optional]
  class ActiveRecord::Migration
    # rails5 compatibility
    def self.[](*)
      self
    end
  end
end

module Dunlop
  class Engine < ::Rails::Engine
    isolate_namespace Dunlop
    initializer 'dunlop.action_controller' do |app|
      ActiveSupport.on_load :action_controller do
        helper Dunlop::ApplicationHelper if respond_to?(:helper)
      end
    end

    initializer "dunlop.ability", group: 'dunlop' do |app|
      if ability_class = "Ability".safe_constantize and ability_class.respond_to?(:add_dunlop_allowed_authorization_classes!)
        ability_class.add_dunlop_allowed_authorization_classes!
      end
    end

    # add migrations to containing application
    initializer :append_migrations do |app|
      unless app.root.to_s.match root.to_s
        config.paths["db/migrate"].expanded.each do |expanded_path|
          app.config.paths["db/migrate"] << expanded_path
        end
      end
    end
  end
end
