Class: BerkeleyLibrary::Alma::Config
- Inherits:
-
Object
- Object
- BerkeleyLibrary::Alma::Config
- 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
-
.alma_institution_code ⇒ Object
Alma institution code, e.g.
-
.alma_institution_code=(inst_code) ⇒ String
Sets the Alma SRU institution code.
- .alma_permalink_base_uri ⇒ Object
-
.alma_permalink_key ⇒ Object
View state key to use when generating Alma permalinks, e.g.
-
.alma_permalink_key=(permalink_key) ⇒ String
Sets the Alma permalink key.
-
.alma_primo_host ⇒ Object
Alma Primo host, e.g.
-
.alma_primo_host=(hostname) ⇒ String
Sets the Alma Primo hostname.
- .alma_sru_base_uri ⇒ Object
-
.alma_sru_host ⇒ Object
Alma SRU hostname, e.g.
-
.alma_sru_host=(hostname) ⇒ String
Sets the Alma SRU hostname.
- .default! ⇒ Object
- .ensure_configured(*settings) ⇒ Object
-
.missing(*settings) ⇒ Array<Symbol>
Returns the list of missing settings.
Class Method Details
.alma_institution_code ⇒ Object
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
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 |
.alma_permalink_base_uri ⇒ Object
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 |
.alma_permalink_key ⇒ Object
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 |
.alma_permalink_key=(permalink_key) ⇒ String
Sets the Alma permalink key
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_host ⇒ Object
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
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_uri ⇒ Object
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_host ⇒ Object
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
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
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.
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 |