class Qa::Authorities::Local::TableBasedAuthority

Attributes

subauthority[R]

Public Class Methods

check_for_index() click to toggle source
# File lib/qa/authorities/local/table_based_authority.rb, line 8
def check_for_index
  @checked_for_index ||= begin
    conn = ActiveRecord::Base.connection
    if table_or_view_exists? && !conn.indexes(table_name).find { |i| i.name == table_index }
      Rails.logger.error "You've installed local authority tables, but you haven't indexed the label.  " \
        "Rails doesn't support functional indexes in migrations, so you'll have to add this manually:\n" \
        "CREATE INDEX \"#{table_index}\" ON \"#{table_name}\" (local_authority_id, lower(label))\n" \
        "   OR on Sqlite: \n" \
        "CREATE INDEX \"#{table_index}\" ON \"#{table_name}\" (local_authority_id, label collate nocase)\n" \
        "   OR for MySQL use the MSQLTableBasedAuthority instead, since mysql does not support functional indexes."
    end
  end
end
new(subauthority) click to toggle source
Calls superclass method
# File lib/qa/authorities/local/table_based_authority.rb, line 36
def initialize(subauthority)
  super()
  self.class.check_for_index
  @subauthority = subauthority
end

Private Class Methods

table_or_view_exists?() click to toggle source
# File lib/qa/authorities/local/table_based_authority.rb, line 24
def table_or_view_exists?
  conn = ActiveRecord::Base.connection
  if conn.respond_to?(:data_source_exists?)
    conn.data_source_exists?(table_name)
  else
    conn.table_exists?(table_name)
  end
end

Public Instance Methods

all() click to toggle source
# File lib/qa/authorities/local/table_based_authority.rb, line 47
def all
  output_set(base_relation.limit(1000))
end
find(uri) click to toggle source
# File lib/qa/authorities/local/table_based_authority.rb, line 51
def find(uri)
  record = base_relation.find_by(uri: uri)
  return unless record
  output(record)
end

Private Instance Methods

base_relation() click to toggle source
# File lib/qa/authorities/local/table_based_authority.rb, line 59
def base_relation
  Qa::LocalAuthorityEntry.where(local_authority: local_authority)
end
local_authority() click to toggle source
# File lib/qa/authorities/local/table_based_authority.rb, line 71
def local_authority
  Qa::LocalAuthority.find_by_name(subauthority)
end
output(item) click to toggle source
# File lib/qa/authorities/local/table_based_authority.rb, line 67
def output(item)
  { id: item[:uri], label: item[:label] }.with_indifferent_access
end
output_set(set) click to toggle source
# File lib/qa/authorities/local/table_based_authority.rb, line 63
def output_set(set)
  set.map { |item| output(item) }
end