require "rails" module Ddr module Models class Engine < ::Rails::Engine engine_name "ddr_models" config.generators do |g| g.test_framework :rspec g.fixture_replacement :factory_girl g.assets false g.helper false end # # Initializers # initializer "active_fedora.content_model" do ActiveFedora::ContentModel.module_eval do # Returns the first known model for the object is equal to or a # subclass of the object's class. # This bubbles up, e.g., to prevent mis-casting via `.find`. def self.best_model_for(obj) known_models_for(obj).find { |model| model <= obj.class } end end end initializer "active_fedora.finder_methods" do ActiveFedora::FinderMethods.module_eval do # Override tries to cast by default def load_from_fedora(pid, cast) inner = ActiveFedora::DigitalObject.find(klass, pid) obj = klass.allocate.init_with_object(inner) if cast != false obj = obj.adapt_to_cmodel end obj end end end initializer "ddr_models.external_files" do Ddr::Models.external_file_store = ENV["EXTERNAL_FILE_STORE"] Ddr::Models.multires_image_external_file_store = ENV["MULTIRES_IMAGE_EXTERNAL_FILE_STORE"] Ddr::Models.external_file_subpath_pattern = ENV["EXTERNAL_FILE_SUBPATH_PATTERN"] || "--" end # Add custom predicates to ActiveFedora initializer "ddr_models.predicates" do ActiveFedora::Predicates.set_predicates(Ddr::Metadata::PREDICATES) end initializer "ddr_auth.groups" do Warden::Manager.after_set_user do |user, auth, opts| user.groups = Ddr::Auth::Groups.build(user, auth.env) end end # Set superuser group initializer "ddr_auth.superuser" do Ddr::Auth.superuser_group = ENV["SUPERUSER_GROUP"] end initializer "ddr_auth.collection_creators" do Ddr::Auth.collection_creators_group = ENV["COLLECTION_CREATORS_GROUP"] end initializer "ezid_client" do unless Rails.env.production? require "ezid/test_helper" ezid_test_mode! end end end end end