Class: Qa::Authorities::Local::TableBasedAuthority
- Defined in:
- lib/qa/authorities/local/table_based_authority.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#subauthority ⇒ Object
readonly
Returns the value of attribute subauthority.
Class Method Summary collapse
Instance Method Summary collapse
- #all ⇒ Object
- #find(uri) ⇒ Object
-
#initialize(subauthority) ⇒ TableBasedAuthority
constructor
A new instance of TableBasedAuthority.
- #search(q) ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(subauthority) ⇒ TableBasedAuthority
18 19 20 21 |
# File 'lib/qa/authorities/local/table_based_authority.rb', line 18 def initialize() self.class.check_for_index @subauthority = end |
Instance Attribute Details
#subauthority ⇒ Object (readonly)
Returns the value of attribute subauthority.
16 17 18 |
# File 'lib/qa/authorities/local/table_based_authority.rb', line 16 def @subauthority end |
Class Method Details
.check_for_index ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/qa/authorities/local/table_based_authority.rb', line 3 def self.check_for_index @checked_for_index ||= begin conn = ActiveRecord::Base.connection if table_or_view_exists? && !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 end |
Instance Method Details
#all ⇒ Object
28 29 30 |
# File 'lib/qa/authorities/local/table_based_authority.rb', line 28 def all output_set(base_relation.limit(1000)) end |
#find(uri) ⇒ Object
32 33 34 35 36 |
# File 'lib/qa/authorities/local/table_based_authority.rb', line 32 def find(uri) record = base_relation.find_by(uri: uri) return unless record output(record) end |
#search(q) ⇒ Object
23 24 25 26 |
# File 'lib/qa/authorities/local/table_based_authority.rb', line 23 def search(q) return [] if q.blank? output_set(base_relation.where('lower(label) like ?', "#{q.downcase}%").limit(25)) end |