Skip to content

File Free Configuration

mbklein edited this page Apr 23, 2012 · 2 revisions

Why?

The most common method of configuring ActiveFedora is through the use of config files – fedora.yml, solr.yml, and predicate_mappings.yml. However, there may be times when you would rather configure ActiveFedora from code (e.g., within a larger framework that reads or acquires Fedora and Solr configuration info from another source).

How?

To supply an alternate configuration source:

  1. Create a class or module that responds to the following methods:
  2. init(*args) should accept any arguments your class needs in order to discover the configuration info.
  3. fedora_config should return a Hash containing the Fedora connection parameters for the current environment (e.g., a has with the same structure/options of one environment block of fedora.yml)
  4. solr_config should return a Hash containing the Solr connection parameters for the current environment.
  5. predicate_config should return a Hash similar to that described by predicate_mappings.yml.
  6. Assign an instance of that class/module to ActiveFedora.configurator.

Example

class MyAppConfiguration
  def initialize
    @config = {
      :fedora => { :url => 'http://fedoraAdmin:fedoraAdmin@localhost:8983/fedora' },
      :solr => { :url => 'http://localhost:8983/solr' },
      :predicates => JSON.parse(RestClient.get('http://example.edu/dynamically/generated/predicate_mapping.json'))
    }
  end

  def init *args; end

  def fedora_config
    @config[:fedora]
  end

  def solr_config
    @config[:solr]
  end

  def predicate_config
    @config[:predicates]
  end
end

ActiveFedora.configurator = MyAppConfiguration.new

Extending ActiveFedora

If you need to extend ActiveFedora in a way that requires new/different configuration information:

  1. Try to make your changes backward-compatible with reasonable defaults.
  2. If you change the assumed location of a config file, look for it in the old location as a fallback.
  3. If you change the expected structure of an existing config hash, code in the ability to read the old format into the new to play nice with configurators that may live outside the ActiveFedora codebase.
  4. If you make a change that requires a new major configuration source (i.e., something that's not related to Fedora, Solr, or Predicate Mappings):
  5. Have the code that needs it access it through ActiveFedora.configurator.foo_config
  6. Add ActiveFedora::FileConfigurator#foo_config to provide the default implementation.
  7. Document the expected response from foo_config above, on this page.
Clone this wiki locally