Sha256: 53ab6411d7a3f3d44af2c6f9f7233b6159325ac2e63ac81dbbdbd07b8e8e0dc6

Contents?: true

Size: 1.47 KB

Versions: 1

Compression:

Stored size: 1.47 KB

Contents

require 'canard'
require 'rails'

module Canard
  class Railtie < Rails::Railtie

    initializer "canard.no_eager_loading", :before => 'before_eager_loading' do |app|
      ActiveSupport::Dependencies.autoload_paths.reject!{ |path| Canard.load_paths.include?(path) }
      # Don't eagerload our configs, we'll deal with them ourselves
      app.config.eager_load_paths = app.config.eager_load_paths.reject do |path|
        Canard.load_paths.include?(path)
      end
      if app.config.respond_to?(:watchable_dirs)
        app.config.watchable_dirs.merge! Hash[ Canard.load_paths.product([[:rb]]) ]
      end
    end

    initializer "canard.active_record" do |app|
      ActiveSupport.on_load :active_record do
        require 'canard/adapters/active_record'
        Canard::Abilities.default_path = File.expand_path('app/abilities', Rails.root)
        extend Canard::UserModel
        Canard.find_abilities
      end
    end

    initializer "canard.mongoid" do |app|
      require 'canard/adapters/mongoid' if defined?(Mongoid)
    end

    initializer "canard.abilities_reloading", :after => "action_dispatch.configure" do |app|
      reloader = rails5? ? ActiveSupport::Reloader : ActionDispatch::Reloader
      if reloader.respond_to?(:to_prepare)
        reloader.to_prepare { Canard.find_abilities }
      end
    end

    rake_tasks do
      load File.expand_path('../../tasks/canard.rake', __FILE__)
    end

    private

    def rails5?
      ActionPack::VERSION::MAJOR == 5
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
canard-0.5.0.pre lib/canard/railtie.rb