Class: Giblish::RequestManager

Inherits:
Object
  • Object
show all
Defined in:
lib/giblish/search/request_manager.rb

Overview

A gateway class that implements everything needed to produce an html page with search results given a search request.

The class implements internal caching for better performance. It is thus probably wise to instantiate this class once and then use that instance for all subsequent search queries.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri_mappings, html_generator = nil) ⇒ RequestManager

url_path_mappings

a Hash with mappings from url paths to

local file system directories.

html_generator

an object that generates html by implementing

the method ‘def response(search_result, css_path = nil)’. See eg DefaultHtmlGenerator. If nil, a DefaultHtmlGenerator is used.



81
82
83
84
85
# File 'lib/giblish/search/request_manager.rb', line 81

def initialize(uri_mappings, html_generator = nil)
  @uri_mappings = uri_mappings || {"/" => "/var/www/html/"}

  @html_generator = html_generator || DefaultHtmlGenerator.new
end

Class Method Details

.searcherObject



105
106
107
# File 'lib/giblish/search/request_manager.rb', line 105

def searcher
  @searcher ||= TextSearcher.new(SearchRepoCache.new)
end

Instance Method Details

#response(search_params) ⇒ Object

Return an html page with the search result from the given query.

search_params

a Hash containing the parameters of the search query.



90
91
92
93
# File 'lib/giblish/search/request_manager.rb', line 90

def response(search_params)
  sp = SearchParameters.from_hash(search_params, uri_mappings: @uri_mappings)
  @html_generator.response(searcher.search(sp), sp.css_path)
end