Class: Dbwatcher::Storage::Session

Inherits:
Object
  • Object
show all
Defined in:
lib/dbwatcher/storage/session.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs = {}) ⇒ Session

Returns a new instance of Session.



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/dbwatcher/storage/session.rb', line 8

def initialize(attrs = {})
  # Set default values
  @changes = []
  @metadata = {}

  # Set provided attributes
  attrs.each do |key, value|
    setter_method = "#{key}="
    send(setter_method, value) if respond_to?(setter_method)
  end
end

Instance Attribute Details

#changesObject

Returns the value of attribute changes.



6
7
8
# File 'lib/dbwatcher/storage/session.rb', line 6

def changes
  @changes
end

#ended_atObject

Returns the value of attribute ended_at.



6
7
8
# File 'lib/dbwatcher/storage/session.rb', line 6

def ended_at
  @ended_at
end

#idObject

Returns the value of attribute id.



6
7
8
# File 'lib/dbwatcher/storage/session.rb', line 6

def id
  @id
end

#metadataObject

Returns the value of attribute metadata.



6
7
8
# File 'lib/dbwatcher/storage/session.rb', line 6

def 
  @metadata
end

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/dbwatcher/storage/session.rb', line 6

def name
  @name
end

#started_atObject

Returns the value of attribute started_at.



6
7
8
# File 'lib/dbwatcher/storage/session.rb', line 6

def started_at
  @started_at
end

Instance Method Details

#summaryObject



36
37
38
39
40
41
42
43
44
# File 'lib/dbwatcher/storage/session.rb', line 36

def summary
  return {} unless changes.is_a?(Array)

  valid_changes = filter_valid_changes
  group_changes_by_operation(valid_changes)
rescue StandardError => e
  warn "Failed to calculate session summary: #{e.message}"
  {}
end

#to_hObject



20
21
22
23
24
25
26
27
28
29
# File 'lib/dbwatcher/storage/session.rb', line 20

def to_h
  {
    id: id,
    name: name,
    metadata: ,
    started_at: started_at,
    ended_at: ended_at,
    changes: changes
  }
end

#to_paramObject

Used by Rails URL helpers to convert the object to a URL parameter



32
33
34
# File 'lib/dbwatcher/storage/session.rb', line 32

def to_param
  id.to_s
end