-
Notifications
You must be signed in to change notification settings - Fork 63
File Free Configuration
mbklein edited this page Apr 23, 2012
·
2 revisions
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).
To supply an alternate configuration source:
- Create a class or module that responds to the following methods:
-
init(*args)
should accept any arguments your class needs in order to discover the configuration info. -
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 offedora.yml
) -
solr_config
should return a Hash containing the Solr connection parameters for the current environment. -
predicate_config
should return a Hash similar to that described bypredicate_mappings.yml
. - Assign an instance of that class/module to
ActiveFedora.configurator
.
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
If you need to extend ActiveFedora in a way that requires new/different configuration information:
- Try to make your changes backward-compatible with reasonable defaults.
- If you change the assumed location of a config file, look for it in the old location as a fallback.
- 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.
- 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):
- Have the code that needs it access it through
ActiveFedora.configurator.foo_config
- Add
ActiveFedora::FileConfigurator#foo_config
to provide the default implementation. - Document the expected response from
foo_config
above, on this page.