Class: Mei::TermsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- Mei::TermsController
- Defined in:
- app/controllers/mei/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 authotirty classes inherit from a super class so they implement the same methods.
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.app_root ⇒ Object
37 38 39 40 41 42 |
# File 'app/controllers/mei/terms_controller.rb', line 37 def self.app_root return @app_root if @app_root @app_root = Rails.root if defined?(Rails) and defined?(Rails.root) @app_root ||= APP_ROOT if defined?(APP_ROOT) @app_root ||= '.' end |
.config_path ⇒ Object
52 53 54 |
# File 'app/controllers/mei/terms_controller.rb', line 52 def self.config_path File.join(app_root, 'config', 'mei.yml') end |
.env ⇒ Object
44 45 46 47 48 49 50 |
# File 'app/controllers/mei/terms_controller.rb', line 44 def self.env return @env if @env #The following commented line always returns "test" in a rails c production console. Unsure of how to fix this yet... #@env = ENV["RAILS_ENV"] = "test" if ENV @env ||= Rails.env if defined?(Rails) and defined?(Rails.root) @env ||= 'development' end |
.mei_config ⇒ Object
32 33 34 35 |
# File 'app/controllers/mei/terms_controller.rb', line 32 def self.mei_config @config ||= YAML::load(File.open(config_path))[env] .with_indifferent_access end |
Instance Method Details
#query ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'app/controllers/mei/terms_controller.rb', line 9 def query s = params.fetch("q", "") e = params.fetch("e", "") field = params[:term] ldf_server = Mei::TermsController.mei_config[:ldf_server] selected_config = Mei::TermsController.mei_config[:form_fields].select { |item| item["id"] == field} return [] if selected_config.blank? hits = case selected_config.first["adapter"].to_sym when :lcsh Mei::LcshSubjectResource.find(s,e,selected_config.first["solr_field"]) when :geonames Mei::GeoNamesResource.find(s,e,selected_config.first["solr_field"]) when :homosaurus Mei::HomosaurusSubjectResource.find(s,e,selected_config.first["solr_field"]) else [] end render json: hits end |