Class: Dbwatcher::Storage::SessionOperations

Inherits:
Object
  • Object
show all
Includes:
Concerns::DataNormalizer
Defined in:
lib/dbwatcher/storage/session_operations.rb

Instance Method Summary collapse

Methods included from Concerns::DataNormalizer

#extract_value, #normalize_change, #normalize_hash_keys, #normalize_operation, #normalize_record_id, #normalize_session_data, #normalize_table_name, #normalize_timestamp

Constructor Details

#initialize(sessions_path, index_file) ⇒ SessionOperations

Returns a new instance of SessionOperations.



8
9
10
11
# File 'lib/dbwatcher/storage/session_operations.rb', line 8

def initialize(sessions_path, index_file)
  @sessions_path = sessions_path
  @index_file = index_file
end

Instance Method Details

#apply_session_limits(sessions) ⇒ Object



29
30
31
32
33
34
# File 'lib/dbwatcher/storage/session_operations.rb', line 29

def apply_session_limits(sessions)
  max_sessions = Dbwatcher.configuration.max_sessions
  return sessions unless max_sessions&.positive?

  sessions.first(max_sessions)
end

#build_session_summary(session) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/dbwatcher/storage/session_operations.rb', line 17

def build_session_summary(session)
  session_data = normalize_session_data(session)

  {
    id: session_data[:id],
    name: session_data[:name],
    started_at: session_data[:started_at],
    ended_at: session_data[:ended_at],
    change_count: (session_data[:changes] || []).count
  }
end

#session_file_path(session_id) ⇒ Object



13
14
15
# File 'lib/dbwatcher/storage/session_operations.rb', line 13

def session_file_path(session_id)
  File.join(@sessions_path, "#{session_id}.json")
end