Module: Slimmer::Headers

Defined in:
lib/slimmer/headers.rb

Constant Summary collapse

InvalidHeader =
Class.new(RuntimeError)
HEADER_PREFIX =
"X-Slimmer".freeze
SLIMMER_HEADER_MAPPING =
{
  application_name: "Application-Name",
  format: "Format",
  page_owner: "Page-Owner",
  organisations: "Organisations",
  world_locations: "World-Locations",
  result_count: "Result-Count",
  search_parameters: "Search-Parameters",
  section: "Section",
  skip: "Skip",
  template: "Template",
  remove_search: "Remove-Search",
  show_accounts: "Show-Accounts",
}.freeze
APPLICATION_NAME_HEADER =
"#{HEADER_PREFIX}-#{SLIMMER_HEADER_MAPPING[:application_name]}".freeze
FORMAT_HEADER =
"#{HEADER_PREFIX}-#{SLIMMER_HEADER_MAPPING[:format]}".freeze
ORGANISATIONS_HEADER =
"#{HEADER_PREFIX}-#{SLIMMER_HEADER_MAPPING[:organisations]}".freeze
WORLD_LOCATIONS_HEADER =
"#{HEADER_PREFIX}-#{SLIMMER_HEADER_MAPPING[:world_locations]}".freeze
PAGE_OWNER_HEADER =
"#{HEADER_PREFIX}-#{SLIMMER_HEADER_MAPPING[:page_owner]}".freeze
RESULT_COUNT_HEADER =
"#{HEADER_PREFIX}-#{SLIMMER_HEADER_MAPPING[:result_count]}".freeze
SEARCH_PATH_HEADER =
"#{HEADER_PREFIX}-Search-Path".freeze
SEARCH_PARAMETERS_HEADER =
"#{HEADER_PREFIX}-#{SLIMMER_HEADER_MAPPING[:search_parameters]}".freeze
SKIP_HEADER =
"#{HEADER_PREFIX}-#{SLIMMER_HEADER_MAPPING[:skip]}".freeze
TEMPLATE_HEADER =
"#{HEADER_PREFIX}-#{SLIMMER_HEADER_MAPPING[:template]}".freeze
REMOVE_SEARCH_HEADER =
"#{HEADER_PREFIX}-#{SLIMMER_HEADER_MAPPING[:remove_search]}".freeze
SHOW_ACCOUNTS_HEADER =
"#{HEADER_PREFIX}-#{SLIMMER_HEADER_MAPPING[:show_accounts]}".freeze

Instance Method Summary collapse

Instance Method Details

#set_slimmer_headers(hash) ⇒ Object

Set the “slimmer headers” to configure the page

Parameters:

  • hash (Hash)

    the options

Options Hash (hash):

  • application_name (String)
  • format (String)
  • organisations (String)
  • page_owner (String)
  • remove_search (String)
  • result_count (String)
  • search_parameters (String)
  • section (String)
  • show_accounts (String)
  • skip (String)
  • template (String)
  • world_locations (String)

Raises:



77
78
79
80
81
82
83
84
# File 'lib/slimmer/headers.rb', line 77

def set_slimmer_headers(hash)
  raise InvalidHeader if (hash.keys - SLIMMER_HEADER_MAPPING.keys).any?

  SLIMMER_HEADER_MAPPING.each do |hash_key, header_suffix|
    value = hash[hash_key]
    headers["#{HEADER_PREFIX}-#{header_suffix}"] = value.to_s if value
  end
end