class BerkeleyLibrary::Alma::Config

Constants

ALL_SETTINGS

Public Class Methods

alma_institution_code() click to toggle source

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
alma_institution_code=(inst_code) click to toggle source

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
alma_primo_host() click to toggle source

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
alma_primo_host=(hostname) click to toggle source

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
alma_sru_base_uri() click to toggle source
# 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_host() click to toggle source

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
alma_sru_host=(hostname) click to toggle source

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
default!() click to toggle source
# 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
ensure_configured(*settings) click to toggle source
# 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
missing(*settings) click to toggle source

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

clear!() click to toggle source
# 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
rails_config() click to toggle source
# File lib/berkeley_library/alma/config.rb, line 146
def rails_config
  return unless defined?(Rails)
  return unless (application = Rails.application)

  application.config
end
set?(setting) click to toggle source
# File lib/berkeley_library/alma/config.rb, line 153
def set?(setting)
  !Config.send(setting).nil?
end
sru_base_uri_for(domain, inst_code) click to toggle source
# 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
value_from_rails_config(sym) click to toggle source

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