Class: Qa::TermsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- Qa::TermsController
- Defined in:
- app/controllers/qa/terms_controller.rb
Overview
This controller is used for all requests to all authorities. It will verify params and figure out which class to instantiate based on the “vocab” param. All the authority classes inherit from a super class so they implement the same methods.
Instance Method Summary collapse
- #check_query_param ⇒ Object
- #check_vocab_param ⇒ Object
-
#index ⇒ Object
If the subauthority supports it, return a list of all terms in the authority.
- #init_authority ⇒ Object
-
#search ⇒ Object
Return a list of terms based on a query.
-
#show ⇒ Object
If the subauthority supports it, return all the information for a given term.
Instance Method Details
#check_query_param ⇒ Object
56 57 58 |
# File 'app/controllers/qa/terms_controller.rb', line 56 def check_query_param head :not_found unless params[:q].present? end |
#check_vocab_param ⇒ Object
31 32 33 |
# File 'app/controllers/qa/terms_controller.rb', line 31 def check_vocab_param head :not_found unless params[:vocab].present? end |
#index ⇒ Object
If the subauthority supports it, return a list of all terms in the authority
11 12 13 14 15 16 17 |
# File 'app/controllers/qa/terms_controller.rb', line 11 def index render json: begin @authority.all rescue NotImplementedError nil end end |
#init_authority ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'app/controllers/qa/terms_controller.rb', line 35 def begin mod = .camelize.constantize rescue NameError logger.warn "Unable to initialize authority #{}" head :not_found return end begin @authority = if mod.is_a? Class mod.new else raise Qa::MissingSubAuthority, "No sub-authority provided" if params[:subauthority].blank? mod.(params[:subauthority]) end rescue Qa::InvalidSubAuthority, Qa::MissingSubAuthority => e logger.warn e. head :not_found end end |
#search ⇒ Object
Return a list of terms based on a query
20 21 22 23 |
# File 'app/controllers/qa/terms_controller.rb', line 20 def search terms = @authority.method(:search).arity == 2 ? @authority.search(url_search, self) : @authority.search(url_search) render json: terms end |
#show ⇒ Object
If the subauthority supports it, return all the information for a given term
26 27 28 29 |
# File 'app/controllers/qa/terms_controller.rb', line 26 def show term = @authority.find(params[:id]) render json: term end |