Class: Qa::Authorities::Local::TableBasedAuthority

Inherits:
Base
  • Object
show all
Defined in:
lib/qa/authorities/local/table_based_authority.rb

Direct Known Subclasses

MysqlTableBasedAuthority

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#full_record

Constructor Details

#initialize(subauthority) ⇒ TableBasedAuthority

Returns a new instance of TableBasedAuthority.



16
17
18
# File 'lib/qa/authorities/local/table_based_authority.rb', line 16

def initialize(subauthority)
  @subauthority = subauthority
end

Instance Attribute Details

#subauthorityObject (readonly)

Returns the value of attribute subauthority.



14
15
16
# File 'lib/qa/authorities/local/table_based_authority.rb', line 14

def subauthority
  @subauthority
end

Class Method Details

.check_for_indexObject



3
4
5
6
7
8
9
10
11
12
# File 'lib/qa/authorities/local/table_based_authority.rb', line 3

def self.check_for_index
  conn = ActiveRecord::Base.connection
  if conn.table_exists?('local_authority_entries') && !conn.indexes('local_authority_entries').find { |i| i.name == 'index_local_authority_entries_on_lower_label' }
    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 \"index_qa_local_authority_entries_on_lower_label\" ON \"qa_local_authority_entries\" (local_authority_id, lower(label))\n" \
      "   OR on Sqlite: \n" \
      "CREATE INDEX \"index_qa_local_authority_entries_on_lower_label\" ON \"qa_local_authority_entries\" (local_authority_id, label collate nocase)\n" \
      "   OR for MySQL use the MSQLTableBasedAuthority instead, since mysql does not support functional indexes."
  end
end

Instance Method Details

#allObject



25
26
27
# File 'lib/qa/authorities/local/table_based_authority.rb', line 25

def all
  output_set(base_relation.limit(1000))
end

#find(uri) ⇒ Object



29
30
31
32
33
# File 'lib/qa/authorities/local/table_based_authority.rb', line 29

def find(uri)
  record = base_relation.find_by(uri: uri)
  return unless record
  output(record)
end

#search(q) ⇒ Object



20
21
22
23
# File 'lib/qa/authorities/local/table_based_authority.rb', line 20

def search(q)
  return [] if q.blank?
  output_set(base_relation.where('lower(label) like ?', "#{q.downcase}%").limit(25))
end