Class: BerkeleyLibrary::Alma::Config

Inherits:
Object
  • Object
show all
Extended by:
Util
Defined in:
lib/berkeley_library/alma/config.rb

Constant Summary collapse

ALL_SETTINGS =
%i[
  alma_sru_host
  alma_primo_host
  alma_institution_code
  alma_permalink_key
].freeze

Class Method Summary collapse

Class Method Details

.alma_institution_codeObject

Alma institution code, e.g. UC Berkeley = 01UCS_BER



22
23
24
# 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) ⇒ String

Sets the Alma SRU institution code

Parameters:

  • inst_code (String)

    the institution code

Returns:

  • (String)

    the institution code

Raises:

  • ArgumentError if the institution code is nil or empty

  • URI::InvalidURIError if the resulting SRU URI cannot be parsed



82
83
84
85
86
87
# 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


44
45
46
47
48
# 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? in the documentation



34
35
36
# 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

Parameters:

  • permalink_key (String)

    the permalink key

Returns:

  • (String)

    the permalink key

Raises:

  • ArgumentError if the permalink key is nil or empty

  • URI::InvalidURIError if the resulting Primo permalink URI cannot be parsed



95
96
97
98
99
100
# 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_hostObject

Alma Primo host, e.g. UC Berkeley = search.library.berkeley.edu



27
28
29
# 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) ⇒ String

Sets the Alma Primo hostname

Parameters:

  • hostname (String)

    the hostname

Returns:

  • (String)

    the hostname

Raises:

  • ArgumentError if the hostname is nil or empty

  • URI::InvalidURIError if the resulting Primo permalink URI cannot be parsed



69
70
71
72
73
74
# 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_uriObject



38
39
40
41
42
# 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_hostObject

Alma SRU hostname, e.g. UC Berkeley = berkeley.alma.exlibrisgroup.com



17
18
19
# 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) ⇒ String

Sets the Alma SRU hostname

Parameters:

  • hostname (String)

    the hostname

Returns:

  • (String)

    the hostname

Raises:

  • ArgumentError if the hostname is nil or empty

  • URI::InvalidURIError if the resulting SRU URI cannot be parsed



56
57
58
59
60
61
# 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!Object



119
120
121
122
123
124
125
126
127
128
# File 'lib/berkeley_library/alma/config.rb', line 119

def default!
  BerkeleyLibrary::Alma.configure do
    config.tap do |c|
      c.alma_sru_host = ENV.fetch('LIT_ALMA_SRU_HOST', 'berkeley.alma.exlibrisgroup.com')
      c.alma_institution_code = ENV.fetch('LIT_ALMA_INSTITUTION_CODE', '01UCS_BER')
      c.alma_primo_host = ENV.fetch('LIT_ALMA_PRIMO_HOST', 'search.library.berkeley.edu')
      c.alma_permalink_key = ENV.fetch('LIT_ALMA_PERMALINK_KEY', 'iqob43')
    end
  end
end

.ensure_configured(*settings) ⇒ Object

Raises:

  • (ArgumentError)


113
114
115
116
117
# 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) ⇒ Array<Symbol>

Returns the list of missing settings.

Returns:

  • (Array<Symbol>)

    the missing settings.



104
105
106
107
108
109
110
111
# 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