class Lurker::ServicePresenter
An BasePresenter for Lurker::Service
Attributes
service[R]
Public Class Methods
new(service, options = {}, &block)
click to toggle source
Calls superclass method
Lurker::BasePresenter::new
# File lib/lurker/presenters/service_presenter.rb, line 11 def initialize(service, options = {}, &block) super(options) @service = service @filtering_block = block end
Public Instance Methods
default_domain()
click to toggle source
# File lib/lurker/presenters/service_presenter.rb, line 42 def default_domain return service_domains.to_a[0][1] if service_domains.present? '/' end
default_request_media_type()
click to toggle source
# File lib/lurker/presenters/service_presenter.rb, line 52 def default_request_media_type request_media_types[0] end
documentation()
click to toggle source
# File lib/lurker/presenters/service_presenter.rb, line 29 def documentation markup @service.documentation end
domains()
click to toggle source
# File lib/lurker/presenters/service_presenter.rb, line 37 def domains return service_domains if service_domains.present? { '/' => 'Local' } end
endpoints()
click to toggle source
# File lib/lurker/presenters/service_presenter.rb, line 81 def endpoints unless @endpoints @endpoints = [] prefix = nil service.endpoints.sort_by(&:endpoint_path).each do |endpoint| presenter = Lurker::EndpointPresenter.new(endpoint, options) presenter.service_presenter = self if @filtering_block presenter = @filtering_block.call(presenter) next if presenter.nil? end current_prefix = presenter.prefix @endpoints << [] if prefix != current_prefix @endpoints.last << presenter prefix = current_prefix end end @endpoints end
endpoints_by_prefix()
click to toggle source
# File lib/lurker/presenters/service_presenter.rb, line 107 def endpoints_by_prefix @endpoints_by_prefix ||= begin hash = Hash.new { |h, k| h[k] = Array.new } service.endpoints.sort_by(&:endpoint_path).each do |endpoint| presenter = Lurker::EndpointPresenter.new(endpoint, options) presenter.service_presenter = self if @filtering_block presenter = @filtering_block.call(presenter) next if presenter.nil? end hash[presenter.prefix] << presenter end hash end end
lurker()
click to toggle source
# File lib/lurker/presenters/service_presenter.rb, line 77 def lurker @lurker ||= options[:lurker] || '' end
name_as_link(options = {})
click to toggle source
# File lib/lurker/presenters/service_presenter.rb, line 56 def name_as_link(options = {}) path = index_path '<a href="%s">%s %s</a>' % [path, options[:prefix], service.name] end
request_media_types()
click to toggle source
# File lib/lurker/presenters/service_presenter.rb, line 47 def request_media_types return service.request_media_types if service.request_media_types.present? ['application/x-www-form-urlencoded'] end
slug_name()
click to toggle source
# File lib/lurker/presenters/service_presenter.rb, line 61 def slug_name @slug_name ||= service.name.downcase.gsub(/[ \/]/, '_') end
title()
click to toggle source
# File lib/lurker/presenters/service_presenter.rb, line 33 def title "#{name}" end
to_html(options={}, &block)
click to toggle source
# File lib/lurker/presenters/service_presenter.rb, line 17 def to_html(options={}, &block) controller = Lurker::RenderingController.new controller.service_presenter = self controller.render_to_string 'index', options end
to_print(options = {})
click to toggle source
# File lib/lurker/presenters/service_presenter.rb, line 23 def to_print(options = {}) controller = Lurker::RenderingController.new controller.service_presenter = self controller.render_to_string 'all', { layout: 'print' }.merge(options) end
url(extension = ".html")
click to toggle source
# File lib/lurker/presenters/service_presenter.rb, line 69 def url(extension = ".html") '%s-%s%s' % [@endpoint.path, @endpoint.verb, extension] end
url_name()
click to toggle source
# File lib/lurker/presenters/service_presenter.rb, line 65 def url_name @url_name ||= name.gsub(/[^a-z0-9\-_]+/i, '_') end
Private Instance Methods
service_domains()
click to toggle source
# File lib/lurker/presenters/service_presenter.rb, line 127 def service_domains service.domains.try(:to_hash) || {} end