Class: Qa::LinkedData::AuthorityService

Inherits:
Object
  • Object
show all
Defined in:
lib/qa/linked_data/authority_service.rb

Class Method Summary collapse

Class Method Details

.authority_config(authname) ⇒ Hash

Get the configuration for an authority

Parameters:

  • name (String)

    of the authority

Returns:

  • (Hash)

    configuration for the specified authority



55
56
57
# File 'lib/qa/linked_data/authority_service.rb', line 55

def self.authority_config(authname)
  authority_configs[authname]
end

.authority_configsArray<String>

Get the list of names of the loaded authorities

Returns:

  • (Array<String>)

    all loaded authority configurations



48
49
50
# File 'lib/qa/linked_data/authority_service.rb', line 48

def self.authority_configs
  Qa.config.linked_data_authority_configs
end

.authority_detailsArray<String>

Get the list of names and details of the loaded authorities

Returns:

  • (Array<String>)

    names of the authority config files that are currently loaded



67
68
69
70
71
# File 'lib/qa/linked_data/authority_service.rb', line 67

def self.authority_details
  details = []
  authority_names.each { |auth_name| details << Qa::Authorities::LinkedData::Config.new(auth_name).authority_info }
  details.flatten
end

.authority_namesArray<String>

Get the list of names of the loaded authorities

Returns:

  • (Array<String>)

    names of the authority config files that are currently loaded



61
62
63
# File 'lib/qa/linked_data/authority_service.rb', line 61

def self.authority_names
  authority_configs.keys.sort
end

.load_assign_fast_configObject

similar to the above; these settings are for getting (non-linked-data) FAST subject headings from OCLC.



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/qa/linked_data/authority_service.rb', line 25

def self.load_assign_fast_config
  assign_fast_auth_cfg = {}
  # assign_fast settings
  Dir[File.join(Qa::Engine.root, 'config', 'authorities', 'assign_fast', '*.json')].each do |fn|
    process_config_file(file_path: fn, config_hash: assign_fast_auth_cfg)
  end
  # Optional local (app) assign_fast settings overrides
  Dir[Rails.root.join('config', 'authorities', 'assign_fast', '*.json')].each do |fn|
    process_config_file(file_path: fn, config_hash: assign_fast_auth_cfg)
  end
  Qa.config.assign_fast_authority_configs = assign_fast_auth_cfg
end

.load_authoritiesObject



5
6
7
8
# File 'lib/qa/linked_data/authority_service.rb', line 5

def self.load_authorities
  load_linked_data_config
  load_assign_fast_config
end

.load_linked_data_configObject

Load or reload the linked data configuration files



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/qa/linked_data/authority_service.rb', line 11

def self.load_linked_data_config
  ld_auth_cfg = {}
  # Linked data settings
  Dir[File.join(Qa::Engine.root, 'config', 'authorities', 'linked_data', '*.json')].each do |fn|
    process_config_file(file_path: fn, config_hash: ld_auth_cfg)
  end
  # Optional local (app) linked data settings overrides
  Dir[Rails.root.join('config', 'authorities', 'linked_data', '*.json')].each do |fn|
    process_config_file(file_path: fn, config_hash: ld_auth_cfg)
  end
  Qa.config.linked_data_authority_configs = ld_auth_cfg
end

.process_config_file(file_path:, config_hash:) ⇒ Object

load settings into a configuration hash:



39
40
41
42
43
44
# File 'lib/qa/linked_data/authority_service.rb', line 39

def self.process_config_file(file_path:, config_hash:)
  file_key = File.basename(file_path, '.json').upcase.to_sym
  json = File.read(File.expand_path(file_path, __FILE__))
  cfg = JSON.parse(json).deep_symbolize_keys
  config_hash[file_key] = cfg
end