Class: RailsInfo::Logs::ServerPresenter

Inherits:
Presenter
  • Object
show all
Defined in:
app/presenters/rails_info/logs/server_presenter.rb

Instance Method Summary collapse

Methods inherited from Presenter

#subject=

Constructor Details

#initialize(subject, options = {}) ⇒ ServerPresenter

Returns a new instance of ServerPresenter.



2
3
4
5
6
# File 'app/presenters/rails_info/logs/server_presenter.rb', line 2

def initialize(subject, options = {})
  super(subject, options)
  
  @rails_info_log = ::RailsInfo::Logs::Server.new(log: params[:log], debug: params[:debug])
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class RailsInfo::Presenter

Instance Method Details

#accordionObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/presenters/rails_info/logs/server_presenter.rb', line 8

def accordion
  @action_index = 0

   :div, id: 'actions', class: 'accordions' do
    html = ''
    
    @rails_info_log.hash.keys.reverse.each do |action|
      tabs = @rails_info_log.hash[action]
      action_presenter = ::RailsInfo::Logs::Server::ActionPresenter.new(
        @subject, name: action, tabs_data: tabs, index: @action_index
      )
      @action_index += 1
      html += raw action_presenter.tabs
    end  
    
    raw html
  end  
end

#write_bodyObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'app/presenters/rails_info/logs/server_presenter.rb', line 49

def write_body
  tab_index = 0
  
  html = ''
  
  @rails_info_log.writes.each do |table_name,data|
    html +=  :div, id: "writes-#{tab_index}" do
      raw render partial: 'rails_info/logs/server/table', locals: { sub_content: data }
    end
    
    tab_index += 1
  end
  
  # free memory
  @rails_info_log = nil
  
  html
end

#write_navigationObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/presenters/rails_info/logs/server_presenter.rb', line 33

def write_navigation
  tab_index = 0
  
   :ul do
    elements = ''
    
    @rails_info_log.writes.each do |table_name,data|
      elements +=  :li, link_to(table_name, "#writes-#{tab_index}")
      
      tab_index += 1
    end
    
    raw elements
  end
end

#write_tabsObject



27
28
29
30
31
# File 'app/presenters/rails_info/logs/server_presenter.rb', line 27

def write_tabs
   :div, class: 'tabs', id: 'writes' do
    raw(write_navigation) + raw(write_body)
  end
end