Class: ActiveFedora::FileConfigurator
- Inherits:
-
Object
- Object
- ActiveFedora::FileConfigurator
- Extended by:
- Deprecation
- Defined in:
- lib/active_fedora/file_configurator.rb
Instance Attribute Summary collapse
-
#config_env ⇒ Object
Options allowed in fedora.yml first level is the environment (e.g. development, test, production and any custom environments you may have) the second level has these keys: 1.
-
#config_options ⇒ Object
readonly
Returns the value of attribute config_options.
-
#fedora_config_path ⇒ Object
readonly
Returns the value of attribute fedora_config_path.
-
#predicate_mappings_config_path ⇒ Object
readonly
Returns the value of attribute predicate_mappings_config_path.
-
#solr_config_path ⇒ Object
readonly
Returns the value of attribute solr_config_path.
Instance Method Summary collapse
-
#check_fedora_path_for_solr ⇒ Object
Checks the existing fedora_config.path to see if there is a solr.yml there.
- #config_loaded? ⇒ Boolean
-
#config_path(config_type) ⇒ String
Determine the fedora config file to use.
- #fedora_config ⇒ Object
- #get_config_path(config_type) ⇒ Object
- #init(options = {}) ⇒ Object
-
#initialize ⇒ FileConfigurator
constructor
The configuration hash that gets used by RSolr.connect.
- #load_configs ⇒ Object
- #load_fedora_config ⇒ Object
- #load_solr_config ⇒ Object
- #path ⇒ Object
- #predicate_config ⇒ Object
- #reset! ⇒ Object
- #solr_config ⇒ Object
-
#solr_url(solr_config) ⇒ Object
Given the solr_config that’s been loaded for this environment, determine which solr url to use.
Constructor Details
#initialize ⇒ FileConfigurator
The configuration hash that gets used by RSolr.connect
55 56 57 |
# File 'lib/active_fedora/file_configurator.rb', line 55 def initialize reset! end |
Instance Attribute Details
#config_env ⇒ Object
Options allowed in fedora.yml first level is the environment (e.g. development, test, production and any custom environments you may have) the second level has these keys:
-
url: url including protocol, host, port and path (e.g. 127.0.0.1:8983/fedora)
-
user: username
-
password: password
-
validateChecksum: indicates to the fedora server whether you want to validate checksums when the datastreams are queried.
51 52 53 |
# File 'lib/active_fedora/file_configurator.rb', line 51 def config_env @config_env end |
#config_options ⇒ Object (readonly)
Returns the value of attribute config_options.
52 53 54 |
# File 'lib/active_fedora/file_configurator.rb', line 52 def @config_options end |
#fedora_config_path ⇒ Object (readonly)
Returns the value of attribute fedora_config_path.
52 53 54 |
# File 'lib/active_fedora/file_configurator.rb', line 52 def fedora_config_path @fedora_config_path end |
#predicate_mappings_config_path ⇒ Object (readonly)
Returns the value of attribute predicate_mappings_config_path.
52 53 54 |
# File 'lib/active_fedora/file_configurator.rb', line 52 def predicate_mappings_config_path @predicate_mappings_config_path end |
#solr_config_path ⇒ Object (readonly)
Returns the value of attribute solr_config_path.
52 53 54 |
# File 'lib/active_fedora/file_configurator.rb', line 52 def solr_config_path @solr_config_path end |
Instance Method Details
#check_fedora_path_for_solr ⇒ Object
Checks the existing fedora_config.path to see if there is a solr.yml there
208 209 210 211 212 |
# File 'lib/active_fedora/file_configurator.rb', line 208 def check_fedora_path_for_solr path = ::File.dirname(self.path) + "/solr.yml" return unless ::File.file? path path end |
#config_loaded? ⇒ Boolean
90 91 92 |
# File 'lib/active_fedora/file_configurator.rb', line 90 def config_loaded? @config_loaded || false end |
#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
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/active_fedora/file_configurator.rb', line 176 def config_path(config_type) config_type = config_type.to_s if (config_path = .fetch("#{config_type}_config_path".to_sym, nil)) raise ConfigurationError, "file does not exist #{config_path}" unless ::File.file? config_path return ::File.(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 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.join(ActiveFedora.root, "config", "#{config_type}.yml") if ::File.file? config_path ActiveFedora::Base.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}_config_path => '/path/to/#{config_type}.yml') - or set Rails.root and put #{config_type}.yml into \#{Rails.root}/config." if ActiveFedora::Base.logger return config_path else raise ConfigurationError, "Couldn't load #{config_type} config file!" end end |
#fedora_config ⇒ Object
68 69 70 71 |
# File 'lib/active_fedora/file_configurator.rb', line 68 def fedora_config load_configs @fedora_config end |
#get_config_path(config_type) ⇒ Object
164 165 166 167 |
# File 'lib/active_fedora/file_configurator.rb', line 164 def get_config_path(config_type) Deprecation.warn(FileConfigurator, "get_config_path is deprecated and will be removed in ActiveFedora 10. Use config_path instead.") config_path(config_type) end |
#init(options = {}) ⇒ Object
59 60 61 62 63 64 65 66 |
# File 'lib/active_fedora/file_configurator.rb', line 59 def init( = {}) if .is_a?(String) raise ArgumentError, "Calling ActiveFedora.init with a path as an argument has been removed. Use ActiveFedora.init(:fedora_config_path=>#{})" end reset! @config_options = load_configs end |
#load_configs ⇒ Object
94 95 96 97 98 99 100 101 |
# File 'lib/active_fedora/file_configurator.rb', line 94 def load_configs return if config_loaded? @config_env = ActiveFedora.environment load_fedora_config load_solr_config @config_loaded = true end |
#load_fedora_config ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/active_fedora/file_configurator.rb', line 103 def load_fedora_config return @fedora_config unless @fedora_config.empty? @fedora_config_path = config_path(:fedora) ActiveFedora::Base.logger.info("ActiveFedora: loading fedora config from #{::File.(@fedora_config_path)}") if ActiveFedora::Base.logger begin config_erb = ERB.new(IO.read(@fedora_config_path)).result(binding) rescue StandardError raise("fedora.yml was found, but could not be parsed with ERB. \n#{$ERROR_INFO.inspect}") end begin fedora_yml = YAML.load(config_erb) rescue Psych::SyntaxError => e raise "fedora.yml was found, but could not be parsed. " \ "Error #{e.}" end config = fedora_yml.symbolize_keys cfg = config[ActiveFedora.environment.to_sym] || {} @fedora_config = cfg.is_a?(Array) ? cfg.map(&:symbolize_keys) : cfg.symbolize_keys end |
#load_solr_config ⇒ Object
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/active_fedora/file_configurator.rb', line 127 def load_solr_config return @solr_config unless @solr_config.empty? @solr_config_path = config_path(:solr) ActiveFedora::Base.logger.info "ActiveFedora: loading solr config from #{::File.(@solr_config_path)}" if ActiveFedora::Base.logger begin config_erb = ERB.new(IO.read(@solr_config_path)).result(binding) rescue StandardError raise("solr.yml was found, but could not be parsed with ERB. \n#{$ERROR_INFO.inspect}") end begin solr_yml = YAML.load(config_erb) rescue StandardError raise("solr.yml was found, but could not be parsed.\n") end config = solr_yml.symbolize_keys raise "The #{ActiveFedora.environment.to_sym} environment settings were not found in the solr.yml config. If you already have a solr.yml file defined, make sure it defines settings for the #{ActiveFedora.environment.to_sym} environment" unless config[ActiveFedora.environment.to_sym] config = config[ActiveFedora.environment.to_sym].symbolize_keys @solr_config = { url: solr_url(config) }.merge(config.slice(:update_path, :select_path)) end |
#path ⇒ Object
78 79 80 |
# File 'lib/active_fedora/file_configurator.rb', line 78 def path config_path(:fedora) end |
#predicate_config ⇒ Object
214 215 216 217 |
# File 'lib/active_fedora/file_configurator.rb', line 214 def predicate_config @predicate_config_path ||= build_predicate_config_path YAML.load(::File.open(@predicate_config_path)) if ::File.exist?(@predicate_config_path) end |
#reset! ⇒ Object
82 83 84 85 86 87 88 |
# File 'lib/active_fedora/file_configurator.rb', line 82 def reset! @config_loaded = false # Force reload of configs @fedora_config = {} @solr_config = {} @config_options = {} @predicate_config_path = nil end |
#solr_config ⇒ Object
73 74 75 76 |
# File 'lib/active_fedora/file_configurator.rb', line 73 def solr_config load_configs @solr_config end |
#solr_url(solr_config) ⇒ Object
Given the solr_config that’s been loaded for this environment, determine which solr url to use
152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/active_fedora/file_configurator.rb', line 152 def solr_url(solr_config) return solr_config[:url] if solr_config.key?(:url) return solr_config['url'] if solr_config.key?('url') if @index_full_text == true && solr_config.key?(:fulltext) && solr_config[:fulltext].key?('url') solr_config[:fulltext]['url'] elsif solr_config.key?(:default) && solr_config[:default].key?('url') solr_config[:default]['url'] else raise URI::InvalidURIError end end |