Sha256: 5c50ae1acd7016833e683f059ff25ada1649a8d78175f7f615b860b587d588d1

Contents?: true

Size: 1.97 KB

Versions: 2

Compression:

Stored size: 1.97 KB

Contents

require 'rubygems'
require 'paranoia'
require 'pretender'

module Samvera
  module Persona
    class Engine < ::Rails::Engine
      isolate_namespace Samvera::Persona

      initializer :append_migrations do |app|
        # only add the migrations if they are not already copied
        # via the rake task. Allows gem to work both with the install:migrations
        # and without it.
        if !app.root.to_s.match(root.to_s) &&
           app.root.join('db/migrate').children.none? {|path| path.fnmatch?("*.samvera_persona.rb")}
          config.paths["db/migrate"].expanded.each do |expanded_path|
            app.config.paths["db/migrate"] << expanded_path
          end
        end
      end

      config.generators do |g|
        g.test_framework :rspec, :fixture => false
        g.fixture_replacement :factory_bot, :dir => 'spec/factories'
        g.assets false
        g.helper false
      end

      config.before_initialize do
        config.i18n.load_path += Dir["#{config.root}/config/locales/**/*.yml"]
      end

      config.after_initialize do
        my_engine_root = Samvera::Persona::Engine.root.to_s
        paths = ActionController::Base.view_paths.collect{|p| p.to_s}
        hyrax_path = paths.detect { |path| path.match('/hyrax-') }
        if hyrax_path
          paths = paths.insert(paths.index(hyrax_path), my_engine_root + '/app/views')
        else
          paths = paths.insert(0, my_engine_root + '/app/views')
        end
        ActionController::Base.view_paths = paths
        ::ApplicationController.send :helper, Samvera::Persona::Engine.helpers
        ::ApplicationController.send :include, Samvera::Persona::BecomesBehavior
        ::Devise::InvitationsController.send(:define_method, :after_invite_path_for) do |_resource|
          main_app.persona_users_path
        end
      end

      config.to_prepare do
        User.send :include, Samvera::Persona::SoftDeleteBehavior
        User.send :include, Samvera::Persona::UsernameBehavior
      end

    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
samvera-persona-0.1.5 lib/samvera-persona/engine.rb
samvera-persona-0.1.4 lib/samvera-persona/engine.rb