Class: StackviewDataController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- StackviewDataController
- Defined in:
- app/controllers/stackview_data_controller.rb
Constant Summary collapse
- DefaultStackviewDocAttributes =
stackview doesn’t like it if certain things are blank
{ "measurement_height_numeric" => 23, "shelfrank" => 1, "measurement_page_numeric" => 100 }
Class Method Summary collapse
- .config_for_type(type) ⇒ Object
-
.remove_config_for_type(type) ⇒ Object
mostly for testing.
- .set_config_for_type(type, attributes) ⇒ Object
Instance Method Summary collapse
Class Method Details
.config_for_type(type) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 |
# File 'app/controllers/stackview_data_controller.rb', line 39 def self.config_for_type(type) type = type.to_s config = self._config_for_types[type] unless config raise ArgumentError, "No config found for #{type}" end default = _config_for_types['default'] return config.reverse_merge(default) end |
.remove_config_for_type(type) ⇒ Object
mostly for testing
54 55 56 57 |
# File 'app/controllers/stackview_data_controller.rb', line 54 def self.remove_config_for_type(type) type = type.to_s _config_for_types.delete(type) end |
.set_config_for_type(type, attributes) ⇒ Object
32 33 34 35 36 37 38 |
# File 'app/controllers/stackview_data_controller.rb', line 32 def self.set_config_for_type(type, attributes) type = type.to_s config = (self._config_for_types[type] ||= {}) config.merge! attributes return config end |
Instance Method Details
#config_for_type(type) ⇒ Object
50 51 52 |
# File 'app/controllers/stackview_data_controller.rb', line 50 def config_for_type(type) self.class.config_for_type(type) end |
#fetch ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'app/controllers/stackview_data_controller.rb', line 61 def fetch config = config_for_type( params[:call_number_type] ) fetch_adapter = config[:fetch_adapter].call # Make sure defaults are covered docs = fetch_adapter.fetch(params).collect do |d| d = d.reverse_merge DefaultStackviewDocAttributes # stackview doens't like shelfrank's over 100 d["shelfrank"] = [d["shelfrank"], 100].min d end # add in URLs url_proc = config[:link] || (lambda {|doc| doc["link"]}) docs.each do |doc| doc["link"] = self.instance_exec(doc, &url_proc) end result = {'docs' => docs} result['start'] = "-1" if docs.empty? render :json => result end |