Class: Dmarcurator::Store::Report
- Inherits:
-
Object
- Object
- Dmarcurator::Store::Report
- Defined in:
- lib/dmarcurator/store/report.rb
Instance Attribute Summary collapse
-
#db ⇒ Object
readonly
Returns the value of attribute db.
Class Method Summary collapse
Instance Attribute Details
#db ⇒ Object (readonly)
Returns the value of attribute db.
6 7 8 |
# File 'lib/dmarcurator/store/report.rb', line 6 def db @db end |
Class Method Details
.create_table(db:) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/dmarcurator/store/report.rb', line 8 def self.create_table(db:) puts "Creating table: reports" db.create_table :reports do primary_key :id String :org_name String :email String :extra_contact_info String :dmarc_report_id String :error DateTime :begin_at DateTime :end_at String :policy_domain String :policy_adkim String :policy_aspf String :policy_p String :policy_sp Integer :policy_pct index :dmarc_report_id end end |
.import_parsed(db:, parsed:) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/dmarcurator/store/report.rb', line 30 def self.import_parsed(db:, parsed:) create_table(db: db) if !db.table_exists?(:reports) if db[:reports].where(dmarc_report_id: parsed.dmarc_report_id).count > 0 puts "Report exists; skipping" return end attributes = {} db[:reports].columns.each do |attribute| next if !parsed.respond_to?(attribute) attributes[attribute] = parsed.public_send(attribute) end result = db[:reports].insert(attributes) imported_report_id = db[:reports].select(:id).order('id ASC').limit(1).first[:id] parsed.records.each do |parsed_record| Record.import_parsed(db: db, parsed: parsed_record, report_id: imported_report_id) end puts "Report++" end |