Class: SourceMonitor::Logs::TablePresenter::Row

Inherits:
Object
  • Object
show all
Defined in:
lib/source_monitor/logs/table_presenter.rb

Instance Method Summary collapse

Constructor Details

#initialize(entry, url_helpers) ⇒ Row

Returns a new instance of Row.



7
8
9
10
# File 'lib/source_monitor/logs/table_presenter.rb', line 7

def initialize(entry, url_helpers)
  @entry = entry
  @url_helpers = url_helpers
end

Instance Method Details

#adapterObject



120
121
122
# File 'lib/source_monitor/logs/table_presenter.rb', line 120

def adapter
  entry.scraper_adapter
end

#detail_pathObject



109
110
111
112
113
114
115
116
117
118
# File 'lib/source_monitor/logs/table_presenter.rb', line 109

def detail_path
  case entry.loggable
  when SourceMonitor::FetchLog
    url_helpers.fetch_log_path(entry.loggable)
  when SourceMonitor::ScrapeLog
    url_helpers.scrape_log_path(entry.loggable)
  else
    nil
  end
end

#dom_idObject



12
13
14
# File 'lib/source_monitor/logs/table_presenter.rb', line 12

def dom_id
  "#{type_slug}-#{entry.loggable_id}"
end

#error_messageObject



132
133
134
# File 'lib/source_monitor/logs/table_presenter.rb', line 132

def error_message
  entry.error_message
end

#failure?Boolean

Returns:

  • (Boolean)


128
129
130
# File 'lib/source_monitor/logs/table_presenter.rb', line 128

def failure?
  !success?
end

#fetch?Boolean

Returns:

  • (Boolean)


146
147
148
# File 'lib/source_monitor/logs/table_presenter.rb', line 146

def fetch?
  entry.fetch?
end

#health_check?Boolean

Returns:

  • (Boolean)


154
155
156
# File 'lib/source_monitor/logs/table_presenter.rb', line 154

def health_check?
  entry.health_check?
end

#http_summaryObject



88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/source_monitor/logs/table_presenter.rb', line 88

def http_summary
  if fetch?
    entry.http_status.present? ? entry.http_status.to_s : ""
  elsif scrape?
    parts = []
    parts << entry.http_status.to_s if entry.http_status
    parts << entry.scraper_adapter if entry.scraper_adapter.present?
    parts.compact.join(" · ").presence || ""
  else
    entry.http_status.present? ? entry.http_status.to_s : ""
  end
end

#metrics_summaryObject



101
102
103
104
105
106
107
# File 'lib/source_monitor/logs/table_presenter.rb', line 101

def metrics_summary
  if fetch?
    "+#{entry.items_created.to_i} / ~#{entry.items_updated.to_i} / ✕#{entry.items_failed.to_i}"
  else
    entry.duration_ms.present? ? "#{entry.duration_ms} ms" : ""
  end
end

#primary_labelObject



48
49
50
51
52
53
54
# File 'lib/source_monitor/logs/table_presenter.rb', line 48

def primary_label
  if scrape?
    entry.item&.title.presence || "(untitled)"
  else
    entry.source&.name
  end
end

#primary_pathObject



56
57
58
59
60
61
62
# File 'lib/source_monitor/logs/table_presenter.rb', line 56

def primary_path
  if scrape? && entry.item
    url_helpers.item_path(entry.item)
  elsif entry.source
    url_helpers.source_path(entry.source)
  end
end

#scrape?Boolean

Returns:

  • (Boolean)


150
151
152
# File 'lib/source_monitor/logs/table_presenter.rb', line 150

def scrape?
  entry.scrape?
end

#source_labelObject



80
81
82
# File 'lib/source_monitor/logs/table_presenter.rb', line 80

def source_label
  entry.source&.name
end

#source_pathObject



84
85
86
# File 'lib/source_monitor/logs/table_presenter.rb', line 84

def source_path
  url_helpers.source_path(entry.source) if entry.source
end

#started_atObject



44
45
46
# File 'lib/source_monitor/logs/table_presenter.rb', line 44

def started_at
  entry.started_at
end

#status_labelObject



36
37
38
# File 'lib/source_monitor/logs/table_presenter.rb', line 36

def status_label
  entry.success? ? "Success" : "Failure"
end

#status_variantObject



40
41
42
# File 'lib/source_monitor/logs/table_presenter.rb', line 40

def status_variant
  entry.success? ? :success : :failure
end

#success?Boolean

Returns:

  • (Boolean)


124
125
126
# File 'lib/source_monitor/logs/table_presenter.rb', line 124

def success?
  entry.success?
end

#type_labelObject



16
17
18
19
20
21
22
23
24
# File 'lib/source_monitor/logs/table_presenter.rb', line 16

def type_label
  if fetch?
    "Fetch"
  elsif scrape?
    "Scrape"
  else
    "Health Check"
  end
end

#type_slugObject



136
137
138
139
140
141
142
143
144
# File 'lib/source_monitor/logs/table_presenter.rb', line 136

def type_slug
  if fetch?
    "fetch"
  elsif scrape?
    "scrape"
  else
    "health-check"
  end
end

#type_variantObject



26
27
28
29
30
31
32
33
34
# File 'lib/source_monitor/logs/table_presenter.rb', line 26

def type_variant
  if fetch?
    :fetch
  elsif scrape?
    :scrape
  else
    :health_check
  end
end

#url_hrefObject



72
73
74
75
76
77
78
# File 'lib/source_monitor/logs/table_presenter.rb', line 72

def url_href
  if fetch?
    entry.source&.feed_url
  elsif scrape?
    entry.item&.url
  end
end

#url_labelObject



64
65
66
67
68
69
70
# File 'lib/source_monitor/logs/table_presenter.rb', line 64

def url_label
  if fetch?
    domain_from_feed_url
  elsif scrape?
    entry.item&.url
  end
end