Class: Lurker::ServicePresenter
- Inherits:
-
BasePresenter
show all
- Extended by:
- Forwardable
- Defined in:
- lib/lurker/presenters/service_presenter.rb
Overview
An BasePresenter for Lurker::Service
Instance Attribute Summary collapse
#options
Instance Method Summary
collapse
#css_path, #get_binding, #html_directory, #index_path, #render, #render_erb, #tag_with_anchor, #url_base_path
Constructor Details
#initialize(service, options = {}, &block) ⇒ ServicePresenter
Returns a new instance of ServicePresenter.
9
10
11
12
13
|
# File 'lib/lurker/presenters/service_presenter.rb', line 9
def initialize(service, options = {}, &block)
super(options)
@service = service
@filtering_block = block
end
|
Instance Attribute Details
#service ⇒ Object
Returns the value of attribute service.
3
4
5
|
# File 'lib/lurker/presenters/service_presenter.rb', line 3
def service
@service
end
|
Instance Method Details
#default_domain ⇒ Object
30
31
32
33
|
# File 'lib/lurker/presenters/service_presenter.rb', line 30
def default_domain
return service.domains.to_a[0][1] if service.domains.present?
'/'
end
|
#domains ⇒ Object
25
26
27
28
|
# File 'lib/lurker/presenters/service_presenter.rb', line 25
def domains
return service.domains if service.domains.present?
{ '/' => 'Local'}
end
|
#endpoints ⇒ Object
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/lurker/presenters/service_presenter.rb', line 48
def endpoints
if !@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 ⇒ Object
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
# File 'lib/lurker/presenters/service_presenter.rb', line 74
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
|
#name_as_link(options = {}) ⇒ Object
35
36
37
38
|
# File 'lib/lurker/presenters/service_presenter.rb', line 35
def name_as_link(options = {})
path = index_path
'<a href="%s">%s %s</a>' % [ path, options[:prefix], service.name ]
end
|
#slug_name ⇒ Object
40
41
42
|
# File 'lib/lurker/presenters/service_presenter.rb', line 40
def slug_name
service.name.downcase.gsub(/[ \/]/, '_')
end
|
#title ⇒ Object
21
22
23
|
# File 'lib/lurker/presenters/service_presenter.rb', line 21
def title
"Lurker | #{name}"
end
|
#to_html(&block) ⇒ Object
16
17
18
19
|
# File 'lib/lurker/presenters/service_presenter.rb', line 16
def to_html(&block)
@service_presenter = self
render('index')
end
|
#url(extension = ".html") ⇒ Object
44
45
46
|
# File 'lib/lurker/presenters/service_presenter.rb', line 44
def url(extension = ".html")
'%s-%s%s' % [ @endpoint.path, @endpoint.verb, extension ]
end
|