Module: ActiveFedora
- Includes:
- Loggable
- Defined in:
- lib/active_fedora.rb,
lib/active_fedora.rb,
lib/active_fedora/base.rb,
lib/active_fedora/model.rb,
lib/active_fedora/railtie.rb,
lib/active_fedora/version.rb,
lib/active_fedora/property.rb,
lib/active_fedora/datastream.rb,
lib/active_fedora/relationship.rb,
lib/active_fedora/solr_service.rb,
lib/active_fedora/content_model.rb,
lib/active_fedora/fedora_object.rb,
lib/active_fedora/semantic_node.rb,
lib/active_fedora/metadata_datastream.rb,
lib/active_fedora/rels_ext_datastream.rb,
lib/active_fedora/qualified_dublin_core_datastream.rb
Overview
:nodoc:
Defined Under Namespace
Modules: FedoraObject, MetadataDatastreamHelper, Model, SemanticNode Classes: Base, ContentModel, Datastream, DatastreamConcurrencyException, MetadataDatastream, NokogiriDatastream, ObjectNotFoundError, PredicateMappingsNotFoundError, Property, QualifiedDublinCoreDatastream, Railtie, Relationship, RelsExtDatastream, ServerError, SolrNotInitialized, SolrService, UnregisteredPredicateError
Constant Summary collapse
- VERSION =
"2.3.4"
Class Attribute Summary collapse
-
.config_env ⇒ Object
Returns the value of attribute config_env.
-
.config_options ⇒ Object
readonly
Returns the value of attribute config_options.
-
.fedora_config ⇒ Object
Returns the value of attribute fedora_config.
-
.fedora_config_path ⇒ Object
Returns the value of attribute fedora_config_path.
-
.solr_config ⇒ Object
Returns the value of attribute solr_config.
-
.solr_config_path ⇒ Object
Returns the value of attribute solr_config_path.
Class Method Summary collapse
-
.check_fedora_path_for_solr ⇒ Object
Checks the existing fedora_config_path to see if there is a solr.yml there.
-
.determine_url(config_type, config) ⇒ String
Determines and sets the fedora_config or solr_config.
-
.environment ⇒ String
Determine what environment we’re running in.
- .fedora ⇒ Object
-
.get_config_path(config_type) ⇒ String
Determine the fedora config file to use.
-
.get_solr_url(solr_config) ⇒ Object
Given the solr_config that’s been loaded for this environment, determine which solr url to use.
-
.init(options = {}) ⇒ Object
Initializes ActiveFedora’s connection to Fedora and Solr based on the info in fedora.yml and solr.yml NOTE: this deprecates the use of a solr url in the fedora.yml.
- .load_config(config_type) ⇒ Object
- .load_configs ⇒ Object
- .predicate_config ⇒ Object
- .register_fedora_and_solr ⇒ Object
- .solr ⇒ Object
- .version ⇒ Object
Class Attribute Details
.config_env ⇒ Object
Returns the value of attribute config_env.
38 39 40 |
# File 'lib/active_fedora.rb', line 38 def config_env @config_env end |
.config_options ⇒ Object (readonly)
Returns the value of attribute config_options.
39 40 41 |
# File 'lib/active_fedora.rb', line 39 def @config_options end |
.fedora_config ⇒ Object
Returns the value of attribute fedora_config.
38 39 40 |
# File 'lib/active_fedora.rb', line 38 def fedora_config @fedora_config end |
.fedora_config_path ⇒ Object
Returns the value of attribute fedora_config_path.
38 39 40 |
# File 'lib/active_fedora.rb', line 38 def fedora_config_path @fedora_config_path end |
.solr_config ⇒ Object
Returns the value of attribute solr_config.
38 39 40 |
# File 'lib/active_fedora.rb', line 38 def solr_config @solr_config end |
.solr_config_path ⇒ Object
Returns the value of attribute solr_config_path.
38 39 40 |
# File 'lib/active_fedora.rb', line 38 def solr_config_path @solr_config_path end |
Class Method Details
.check_fedora_path_for_solr ⇒ Object
Checks the existing fedora_config_path to see if there is a solr.yml there
227 228 229 230 231 232 233 234 |
# File 'lib/active_fedora.rb', line 227 def self.check_fedora_path_for_solr path = fedora_config_path.split('/')[0..-2].join('/') + "/solr.yml" if File.file? path return path else return nil end end |
.determine_url(config_type, config) ⇒ String
Determines and sets the fedora_config or solr_config
121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/active_fedora.rb', line 121 def self.determine_url(config_type,config) if config_type == "fedora" # support old-style config if config[environment].fetch("fedora",nil) return config[environment]["fedora"]["url"] if config[environment].fetch("fedora",nil) else return config[environment]["url"] end else return get_solr_url(config[environment]) if config_type == "solr" end end |
.environment ⇒ String
Determine what environment we’re running in. Order of preference is:
-
Rails.env
-
raises an exception if none of these is set
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/active_fedora.rb', line 172 def self.environment if .fetch(:environment,nil) return [:environment] elsif defined?(Rails.env) and !Rails.env.nil? return Rails.env.to_s elsif defined?(ENV['environment']) and !(ENV['environment'].nil?) return ENV['environment'] elsif defined?(ENV['RAILS_ENV']) and !(ENV['RAILS_ENV'].nil?) logger.warn("You're depending on RAILS_ENV for setting your environment. This is deprecated in Rails3. Please use ENV['environment'] for non-rails environment setting: 'rake foo:bar environment=test'") ENV['environment'] = ENV['RAILS_ENV'] return ENV['environment'] else raise "Can't determine what environment to run in!" end end |
.fedora ⇒ Object
240 241 242 |
# File 'lib/active_fedora.rb', line 240 def self.fedora Fedora::Repository.instance end |
.get_config_path(config_type) ⇒ String
Determine the fedora config file to use. Order of preference is:
-
Use the config_options if it exists
-
Look in
Rails.root
/config/fedora.yml -
Look in current working directory/config/fedora.yml
-
Load the default config that ships with this gem
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
# File 'lib/active_fedora.rb', line 195 def self.get_config_path(config_type) config_type = config_type.to_s if (config_path = .fetch("#{config_type}_config_path".to_sym,nil) ) raise ActiveFedoraConfigurationException unless File.file? config_path return config_path end # if solr, attempt to use path where fedora.yml is first if config_type == "solr" && (config_path = check_fedora_path_for_solr) return config_path elsif config_type == "solr" && fedora_config[environment].fetch("solr",nil) logger.warn("DEPRECATION WARNING: You appear to be using a deprecated format for your fedora.yml file. The solr url should be stored in a separate solr.yml file in the same directory as the fedora.yml") raise ActiveFedoraConfigurationException end if defined?(Rails.root) config_path = "#{Rails.root}/config/#{config_type}.yml" return config_path if File.file? config_path end if File.file? "#{Dir.getwd}/config/#{config_type}.yml" return "#{Dir.getwd}/config/#{config_type}.yml" end # Last choice, check for the default config file config_path = File.(File.join(File.dirname(__FILE__), "..", "config", "#{config_type}.yml")) logger.warn "Using the default #{config_type}.yml that comes with active-fedora. If you want to override this, pass the path to #{config_type}.yml to ActiveFedora - ie. ActiveFedora.init(:#{config_type} => '/path/to/#{config_type}.yml) - or set Rails.root and put #{config_type}.yml into \#{Rails.root}/config." return config_path if File.file? config_path raise ActiveFedoraConfigurationException "Couldn't load #{config_type} config file!" end |
.get_solr_url(solr_config) ⇒ Object
Given the solr_config that’s been loaded for this environment, determine which solr url to use
136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/active_fedora.rb', line 136 def self.get_solr_url(solr_config) if @index_full_text == true && solr_config.has_key?('fulltext') && solr_config['fulltext'].has_key?('url') return solr_config['fulltext']['url'] elsif solr_config.has_key?('default') && solr_config['default'].has_key?('url') return solr_config['default']['url'] elsif solr_config.has_key?('url') return solr_config['url'] elsif solr_config.has_key?(:url) return solr_config[:url] else raise URI::InvalidURIError end end |
.init(options = {}) ⇒ Object
Initializes ActiveFedora’s connection to Fedora and Solr based on the info in fedora.yml and solr.yml NOTE: this deprecates the use of a solr url in the fedora.yml
If Rails.env is set, it will use that environment. Defaults to “development”. If :environment is not set, order of preference is
-
Rails.env
-
RAILS_ENV
If :fedora_config_path is not set, it will look in
-
Rails.root
/config -
current working directory/config
-
(default) the fedora.yml shipped with gem
If :solr_config_path is not set, it will
-
look in config_options. If it finds a solr.yml there, it will use it.
-
If it does not find a solr.yml and the fedora.yml contains a solr url, it will raise an configuration error
-
If it does not find a solr.yml and the fedora.yml does not contain a solr url, it will look in:
Rails.root
/config, current working directory/config, then the solr.yml shipped with gem
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/active_fedora.rb', line 70 def self.init( ={} ) logger.level = Logger::ERROR # Make config_options into a Hash if nil is passed in as the value = {} if .nil? # For backwards compatibility, handle cases where config_path (a String) is passed in as the argument rather than a config_options hash # In all other cases, set config_path to config_options[:config_path], which is ok if it's nil if .is_a? String logger.warn "DEPRECATION WARNING: Calling ActiveFedora.init with a path as an argument is deprecated. Use ActiveFedora.init(:config_path=>#{})" @config_options = {:fedora_config_path=>} else @config_options = end @config_env = environment @fedora_config_path = get_config_path(:fedora) load_config(:fedora) @solr_config_path = get_config_path(:solr) load_config(:solr) register_fedora_and_solr # Retrieve the valid path for the predicate mappings config file @predicate_config_path = build_predicate_config_path(File.dirname(fedora_config_path)) end |
.load_config(config_type) ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/active_fedora.rb', line 103 def self.load_config(config_type) config_type = config_type.to_s config_path = self.send("#{config_type}_config_path".to_sym) logger.info("#{config_type.upcase}: loading ActiveFedora.#{config_type}_config from #{File.(config_path)}") config = YAML::load(File.open(config_path)) raise "The #{@config_env.to_s} environment settings were not found in the #{config_type}.yml config. If you already have a #{config_type}.yml file defined, make sure it defines settings for the #{@config_env} environment" unless config[@config_env] config[:url] = determine_url(config_type,config) self.instance_variable_set("@#{config_type}_config", config) config end |
.load_configs ⇒ Object
98 99 100 101 |
# File 'lib/active_fedora.rb', line 98 def self.load_configs load_config(:fedora) load_config(:solr) end |
.predicate_config ⇒ Object
244 245 246 |
# File 'lib/active_fedora.rb', line 244 def self.predicate_config @predicate_config_path ||= build_predicate_config_path end |
.register_fedora_and_solr ⇒ Object
150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/active_fedora.rb', line 150 def self.register_fedora_and_solr # Register Solr logger.info("FEDORA: initializing ActiveFedora::SolrService with solr_config: #{ActiveFedora.solr_config.inspect}") ActiveFedora::SolrService.register(ActiveFedora.solr_config[:url]) logger.info("FEDORA: initialized Solr with ActiveFedora.solr_config: #{ActiveFedora::SolrService.instance.inspect}") logger.info("FEDORA: initializing Fedora with fedora_config: #{ActiveFedora.fedora_config.inspect}") Fedora::Repository.register(ActiveFedora.fedora_config[:url]) logger.info("FEDORA: initialized Fedora as: #{Fedora::Repository.instance.inspect}") end |
.solr ⇒ Object
236 237 238 |
# File 'lib/active_fedora.rb', line 236 def self.solr ActiveFedora::SolrService.instance end |
.version ⇒ Object
248 249 250 |
# File 'lib/active_fedora.rb', line 248 def self.version ActiveFedora::VERSION end |