class Qa::Authorities::Local::FileBasedAuthority

Attributes

subauthority[R]

Public Class Methods

new(subauthority) click to toggle source
Calls superclass method
# File lib/qa/authorities/local/file_based_authority.rb, line 4
def initialize(subauthority)
  super()
  @subauthority = subauthority
end

Public Instance Methods

all() click to toggle source
# File lib/qa/authorities/local/file_based_authority.rb, line 16
def all
  terms.map do |res|
    { id: res[:id], label: res[:term], active: res.fetch(:active, true), uri: res.fetch(:uri, nil) }
      .compact.with_indifferent_access
  end
end
find(id) click to toggle source
# File lib/qa/authorities/local/file_based_authority.rb, line 23
def find(id)
  terms.find { |term| term[:id] == id } || {}
end

Private Instance Methods

normalize_terms(terms) click to toggle source
# File lib/qa/authorities/local/file_based_authority.rb, line 39
def normalize_terms(terms)
  terms.map do |term|
    if term.is_a? String
      { id: term, term: term }.with_indifferent_access
    else
      term[:id] ||= term[:term]
      term
    end
  end
end
subauthority_filename() click to toggle source
# File lib/qa/authorities/local/file_based_authority.rb, line 35
def subauthority_filename
  File.join(Local.subauthorities_path, "#{subauthority}.yml")
end
terms() click to toggle source
# File lib/qa/authorities/local/file_based_authority.rb, line 29
def terms
  subauthority_hash = YAML.load(File.read(subauthority_filename)) # rubocop:disable Security/YAMLLoad # TODO: Explore how to change this to safe_load.  Many tests fail when making this change.
  terms = subauthority_hash.with_indifferent_access.fetch(:terms, [])
  normalize_terms(terms)
end