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.



35
36
37
38
# File 'lib/qa/authorities/local/table_based_authority.rb', line 35

def initialize(subauthority)
  self.class.check_for_index
  @subauthority = subauthority
end

Instance Attribute Details

#subauthorityObject (readonly)

Returns the value of attribute subauthority.



33
34
35
# File 'lib/qa/authorities/local/table_based_authority.rb', line 33

def subauthority
  @subauthority
end

Class Method Details

.check_for_indexObject



8
9
10
11
12
13
14
15
16
17
18
19
# 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

Instance Method Details

#allObject



45
46
47
# File 'lib/qa/authorities/local/table_based_authority.rb', line 45

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

#find(uri) ⇒ Object



49
50
51
52
53
# File 'lib/qa/authorities/local/table_based_authority.rb', line 49

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

#search(q) ⇒ Object



40
41
42
43
# File 'lib/qa/authorities/local/table_based_authority.rb', line 40

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