Class: LogBench::App::State

Inherits:
Object
  • Object
show all
Defined in:
lib/log_bench/app/state.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeState

Returns a new instance of State.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/log_bench/app/state.rb', line 9

def initialize
  self.requests = []
  self.selected = 0
  self.scroll_offset = 0
  self.auto_scroll = true
  self.running = true
  self.focused_pane = :left
  self.detail_scroll_offset = 0
  self.text_selection_mode = false
  self.main_filter = Filter.new
  self.detail_filter = Filter.new
  self.sort = Sort.new
  self.update_available = false
  self.update_version = nil
end

Instance Attribute Details

#auto_scrollObject

Returns the value of attribute auto_scroll.



7
8
9
# File 'lib/log_bench/app/state.rb', line 7

def auto_scroll
  @auto_scroll
end

#detail_filterObject

Returns the value of attribute detail_filter.



6
7
8
# File 'lib/log_bench/app/state.rb', line 6

def detail_filter
  @detail_filter
end

#detail_scroll_offsetObject

Returns the value of attribute detail_scroll_offset.



7
8
9
# File 'lib/log_bench/app/state.rb', line 7

def detail_scroll_offset
  @detail_scroll_offset
end

#main_filterObject

Returns the value of attribute main_filter.



6
7
8
# File 'lib/log_bench/app/state.rb', line 6

def main_filter
  @main_filter
end

#requestsObject

Returns the value of attribute requests.



7
8
9
# File 'lib/log_bench/app/state.rb', line 7

def requests
  @requests
end

#scroll_offsetObject

Returns the value of attribute scroll_offset.



7
8
9
# File 'lib/log_bench/app/state.rb', line 7

def scroll_offset
  @scroll_offset
end

#selectedObject

Returns the value of attribute selected.



7
8
9
# File 'lib/log_bench/app/state.rb', line 7

def selected
  @selected
end

#sortObject

Returns the value of attribute sort.



6
7
8
# File 'lib/log_bench/app/state.rb', line 6

def sort
  @sort
end

#text_selection_modeObject

Returns the value of attribute text_selection_mode.



7
8
9
# File 'lib/log_bench/app/state.rb', line 7

def text_selection_mode
  @text_selection_mode
end

#update_availableObject

Returns the value of attribute update_available.



7
8
9
# File 'lib/log_bench/app/state.rb', line 7

def update_available
  @update_available
end

#update_versionObject

Returns the value of attribute update_version.



7
8
9
# File 'lib/log_bench/app/state.rb', line 7

def update_version
  @update_version
end

Instance Method Details

#add_to_filter(char) ⇒ Object



103
104
105
106
107
108
109
# File 'lib/log_bench/app/state.rb', line 103

def add_to_filter(char)
  if main_filter.active?
    main_filter.add_character(char)
  elsif detail_filter.active?
    detail_filter.add_character(char)
  end
end

#adjust_auto_scroll(visible_height) ⇒ Object



180
181
182
183
184
185
# File 'lib/log_bench/app/state.rb', line 180

def adjust_auto_scroll(visible_height)
  return unless auto_scroll && !filtered_requests.empty?

  self.selected = filtered_requests.size - 1
  self.scroll_offset = [selected - visible_height + 1, 0].max
end

#adjust_scroll_bounds(visible_height) ⇒ Object



187
188
189
190
191
# File 'lib/log_bench/app/state.rb', line 187

def adjust_scroll_bounds(visible_height)
  filtered = filtered_requests
  max_offset = [filtered.size - visible_height, 0].max
  self.scroll_offset = scroll_offset.clamp(0, max_offset)
end

#adjust_scroll_for_selection(visible_height) ⇒ Object



170
171
172
173
174
175
176
177
178
# File 'lib/log_bench/app/state.rb', line 170

def adjust_scroll_for_selection(visible_height)
  return unless left_pane_focused?

  if selected < scroll_offset
    self.scroll_offset = selected
  elsif selected >= scroll_offset + visible_height
    self.scroll_offset = selected - visible_height + 1
  end
end

#backspace_filterObject



111
112
113
114
115
116
117
# File 'lib/log_bench/app/state.rb', line 111

def backspace_filter
  if main_filter.active?
    main_filter.remove_character
  elsif detail_filter.active?
    detail_filter.remove_character
  end
end

#clear_detail_filterObject



65
66
67
68
# File 'lib/log_bench/app/state.rb', line 65

def clear_detail_filter
  detail_filter.clear
  self.detail_scroll_offset = 0
end

#clear_filterObject



59
60
61
62
63
# File 'lib/log_bench/app/state.rb', line 59

def clear_filter
  main_filter.clear
  self.selected = 0
  self.scroll_offset = 0
end

#current_requestObject



144
145
146
147
148
149
# File 'lib/log_bench/app/state.rb', line 144

def current_request
  filtered = filtered_requests
  return nil if selected >= filtered.size || filtered.empty?

  filtered[selected]
end

#cycle_sort_modeObject



70
71
72
# File 'lib/log_bench/app/state.rb', line 70

def cycle_sort_mode
  sort.cycle
end

#detail_filter_modeObject



123
124
125
# File 'lib/log_bench/app/state.rb', line 123

def detail_filter_mode
  detail_filter.active?
end

#dismiss_update_notificationObject



50
51
52
53
# File 'lib/log_bench/app/state.rb', line 50

def dismiss_update_notification
  self.update_available = false
  self.update_version = nil
end

#enter_filter_modeObject



90
91
92
93
94
95
96
# File 'lib/log_bench/app/state.rb', line 90

def enter_filter_mode
  if left_pane_focused?
    main_filter.enter_mode
  else
    detail_filter.enter_mode
  end
end

#exit_filter_modeObject



98
99
100
101
# File 'lib/log_bench/app/state.rb', line 98

def exit_filter_mode
  main_filter.exit_mode
  detail_filter.exit_mode
end

#filter_modeObject



119
120
121
# File 'lib/log_bench/app/state.rb', line 119

def filter_mode
  main_filter.active?
end

#filtered_requestsObject



127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/log_bench/app/state.rb', line 127

def filtered_requests
  filtered = if main_filter.present?
    requests.select do |req|
      main_filter.matches?(req.path) ||
        main_filter.matches?(req.method) ||
        main_filter.matches?(req.controller) ||
        main_filter.matches?(req.action) ||
        main_filter.matches?(req.status) ||
        main_filter.matches?(req.request_id)
    end
  else
    requests
  end

  sort.sort_requests(filtered)
end

#left_pane_focused?Boolean

Returns:

  • (Boolean)


82
83
84
# File 'lib/log_bench/app/state.rb', line 82

def left_pane_focused?
  focused_pane == :left
end


160
161
162
163
164
165
166
167
168
# File 'lib/log_bench/app/state.rb', line 160

def navigate_down
  if left_pane_focused?
    max_index = filtered_requests.size - 1
    self.selected = [selected + 1, max_index].min
    self.auto_scroll = false
  else
    self.detail_scroll_offset += 1
  end
end


151
152
153
154
155
156
157
158
# File 'lib/log_bench/app/state.rb', line 151

def navigate_up
  if left_pane_focused?
    self.selected = [selected - 1, 0].max
    self.auto_scroll = false
  else
    self.detail_scroll_offset = [detail_scroll_offset - 1, 0].max
  end
end

#right_pane_focused?Boolean

Returns:

  • (Boolean)


86
87
88
# File 'lib/log_bench/app/state.rb', line 86

def right_pane_focused?
  focused_pane == :right
end

#running?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/log_bench/app/state.rb', line 25

def running?
  running
end

#set_update_available(version) ⇒ Object



45
46
47
48
# File 'lib/log_bench/app/state.rb', line 45

def set_update_available(version)
  self.update_available = true
  self.update_version = version
end

#stop!Object



29
30
31
# File 'lib/log_bench/app/state.rb', line 29

def stop!
  self.running = false
end

#switch_to_left_paneObject



74
75
76
# File 'lib/log_bench/app/state.rb', line 74

def switch_to_left_pane
  self.focused_pane = :left
end

#switch_to_right_paneObject



78
79
80
# File 'lib/log_bench/app/state.rb', line 78

def switch_to_right_pane
  self.focused_pane = :right
end

#text_selection_mode?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/log_bench/app/state.rb', line 41

def text_selection_mode?
  text_selection_mode
end

#toggle_auto_scrollObject



33
34
35
# File 'lib/log_bench/app/state.rb', line 33

def toggle_auto_scroll
  self.auto_scroll = !auto_scroll
end

#toggle_text_selection_modeObject



37
38
39
# File 'lib/log_bench/app/state.rb', line 37

def toggle_text_selection_mode
  self.text_selection_mode = !text_selection_mode
end

#update_available?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/log_bench/app/state.rb', line 55

def update_available?
  update_available
end