Class: Dmarcurator::Store::Record

Inherits:
Object
  • Object
show all
Defined in:
lib/dmarcurator/store/record.rb

Overview

DMARC report. Contains many records.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#dbObject (readonly)

Returns the value of attribute db.



8
9
10
# File 'lib/dmarcurator/store/record.rb', line 8

def db
  @db
end

Class Method Details

.create_table(db:) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/dmarcurator/store/record.rb', line 10

def self.create_table(db:)
  db.create_table :records do
    primary_key :id
    foreign_key(:report_id, :reports, key: :id)
    String :source_ip
    Integer :count
    String :disposition
    String :policy_result_dkim
    String :policy_result_spf
    String :envelope_to
    String :header_from
    String :auth_dkim_domain
    String :auth_dkim_result
    String :auth_dkim_selector
    String :auth_spf_domain
    String :auth_spf_result
  end
end

.import_parsed(db:, parsed:, report_id:) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/dmarcurator/store/record.rb', line 29

def self.import_parsed(db:, parsed:, report_id:)
  create_table(db: db) if !db.table_exists?(:records)

  attributes = { report_id: report_id }
  db[:records].columns.each do |attribute|
    next if !parsed.respond_to?(attribute)
    attributes[attribute] = parsed.public_send(attribute)
  end
  result = db[:records].insert(attributes)
  STDOUT << "."
end