class BerkeleyLibrary::Alma::Config
Constants
- ALL_SETTINGS
Public Class Methods
Alma
institution code, e.g. UC Berkeley = 01UCS_BER
# File lib/berkeley_library/alma/config.rb, line 22 def alma_institution_code @alma_institution_code ||= value_from_rails_config(:alma_institution_code) end
Sets the Alma
SRU institution code
@param [String] inst_code the institution code @return [String] the institution code @raise ArgumentError if the institution code is nil or empty @raise URI::InvalidURIError if the resulting SRU URI cannot be parsed
# File lib/berkeley_library/alma/config.rb, line 82 def alma_institution_code=(inst_code) raise ArgumentError, "Invalid institution code: #{inst_code.inspect}" if inst_code.nil? || inst_code.empty? sru_uri = sru_base_uri_for('example.org', inst_code) # Catch bad URIs early @alma_institution_code = sru_uri.path.split('/').last end
# File lib/berkeley_library/alma/config.rb, line 44 def alma_permalink_base_uri ensure_configured(:alma_primo_host, :alma_institution_code, :alma_permalink_key) primo_permalink_base_uri_for(alma_primo_host, alma_institution_code, alma_permalink_key) end
View state key to use when generating Alma
permalinks, e.g. ‘iqob43`; see [What is the key in short permalinks?](knowledge.exlibrisgroup.com/Primo/Knowledge_Articles/What_is_the_key_in_short_permalinks%3F) in the documentation
# File lib/berkeley_library/alma/config.rb, line 34 def alma_permalink_key @alma_permalink_key ||= value_from_rails_config(:alma_permalink_key) end
Sets the Alma
permalink key
@param [String] permalink_key the permalink key @return [String] the permalink key @raise ArgumentError if the permalink key is nil or empty @raise URI::InvalidURIError if the resulting Primo permalink URI cannot be parsed
# File lib/berkeley_library/alma/config.rb, line 95 def alma_permalink_key=(permalink_key) raise ArgumentError, "Invalid permalink key: #{permalink_key.inspect}" if permalink_key.nil? || permalink_key.empty? sru_uri = primo_permalink_base_uri_for('example.org', 'XXX', permalink_key) # Catch bad URIs early @alma_permalink_key = sru_uri.path.split('/').last end
Alma
Primo host, e.g. UC Berkeley = search.library.berkeley.edu
# File lib/berkeley_library/alma/config.rb, line 27 def alma_primo_host @alma_primo_host ||= value_from_rails_config(:alma_primo_host) end
Sets the Alma
Primo hostname
@param [String] hostname the hostname @return [String] the hostname @raise ArgumentError if the hostname is nil or empty @raise URI::InvalidURIError if the resulting Primo permalink URI cannot be parsed
# File lib/berkeley_library/alma/config.rb, line 69 def alma_primo_host=(hostname) raise ArgumentError, "Invalid hostname: #{hostname.inspect}" if hostname.nil? || hostname.empty? primo_uri = primo_permalink_base_uri_for(hostname, 'XXX', 'abc123') # Catch bad URIs early @alma_primo_host = primo_uri.host end
# File lib/berkeley_library/alma/config.rb, line 38 def alma_sru_base_uri ensure_configured(:alma_sru_host, :alma_institution_code) sru_base_uri_for(alma_sru_host, alma_institution_code) end
Alma
SRU hostname, e.g. UC Berkeley = berkeley.alma.exlibrisgroup.com
# File lib/berkeley_library/alma/config.rb, line 17 def alma_sru_host @alma_sru_host ||= value_from_rails_config(:alma_sru_host) end
Sets the Alma
SRU hostname
@param [String] hostname the hostname @return [String] the hostname @raise ArgumentError if the hostname is nil or empty @raise URI::InvalidURIError if the resulting SRU URI cannot be parsed
# File lib/berkeley_library/alma/config.rb, line 56 def alma_sru_host=(hostname) raise ArgumentError, "Invalid hostname: #{hostname.inspect}" if hostname.nil? || hostname.empty? sru_uri = sru_base_uri_for(hostname, '') # Catch bad URIs early @alma_sru_host = sru_uri.host end
# File lib/berkeley_library/alma/config.rb, line 119 def default! BerkeleyLibrary::Alma.configure do config.alma_sru_host = ENV.fetch('LIT_ALMA_SRU_HOST', 'berkeley.alma.exlibrisgroup.com') config.alma_institution_code = ENV.fetch('LIT_ALMA_INSTITUTION_CODE', '01UCS_BER') config.alma_primo_host = ENV.fetch('LIT_ALMA_PRIMO_HOST', 'search.library.berkeley.edu') config.alma_permalink_key = ENV.fetch('LIT_ALMA_PERMALINK_KEY', 'iqob43') end end
# File lib/berkeley_library/alma/config.rb, line 113 def ensure_configured(*settings) return if (missing_settings = missing(*settings)).empty? raise ArgumentError, "Missing #{self} configuration settings: #{missing_settings.join(', ')}" end
Returns the list of missing settings. @return [Array<Symbol>] the missing settings.
# File lib/berkeley_library/alma/config.rb, line 104 def missing(*settings) settings = ALL_SETTINGS if settings.empty? [].tap do |unset| settings.each do |setting| unset << setting unless set?(setting) end end end
Private Class Methods
# File lib/berkeley_library/alma/config.rb, line 157 def clear! ALL_SETTINGS.each do |attr| ivar_name = "@#{attr}" next unless instance_variable_defined?(ivar_name) send(:remove_instance_variable, ivar_name) end end
# File lib/berkeley_library/alma/config.rb, line 134 def primo_permalink_base_uri_for(alma_primo_host, inst_code, key) URIs.append("https://#{alma_primo_host}/", 'permalink', inst_code, key) end
# File lib/berkeley_library/alma/config.rb, line 146 def rails_config return unless defined?(Rails) return unless (application = Rails.application) application.config end
# File lib/berkeley_library/alma/config.rb, line 153 def set?(setting) !Config.send(setting).nil? end
# File lib/berkeley_library/alma/config.rb, line 130 def sru_base_uri_for(domain, inst_code) URIs.append("https://#{domain}/view/sru/", inst_code) end
Gets the specified value from the Rails configuraiton @return [Object, nil] the value, or nil if there is no Rails configuration or the value is not set
# File lib/berkeley_library/alma/config.rb, line 140 def value_from_rails_config(sym) return unless (config = rails_config) config.send(sym) end