Module: CertWatch::DomainOwner

Defined in:
lib/cert_watch/domain_owner.rb

Class Method Summary collapse

Class Method Details

.define(options) ⇒ Object


3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/cert_watch/domain_owner.rb', line 3

def self.define(options)
  attribute = options.fetch(:attribute).to_s

  Module.new do
    extend ActiveSupport::Concern

    included do
      after_save do
        if changed.include?(attribute)
          previous_value = changes[attribute].first
          new_value = self[attribute]

          Certificate.find_by(domain: previous_value).try(:abandon)
          Certificate.find_or_create_by(domain: new_value).renew if new_value.present?
        end
      end
    end
  end
end