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
43 44 45 46 47 48 49 50 51 52 53 |
# File 'app/controllers/stackview_data_controller.rb', line 43 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
58 59 60 61 |
# File 'app/controllers/stackview_data_controller.rb', line 58 def self.remove_config_for_type(type) type = type.to_s _config_for_types.delete(type) end |
.set_config_for_type(type, attributes) ⇒ Object
36 37 38 39 40 41 42 |
# File 'app/controllers/stackview_data_controller.rb', line 36 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
54 55 56 |
# File 'app/controllers/stackview_data_controller.rb', line 54 def config_for_type(type) self.class.config_for_type(type) end |
#fetch ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'app/controllers/stackview_data_controller.rb', line 65 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 |