Sha256: 9522ef35a8d9ea88a887e932932db063c3edf154a74baedf68b19b81aeaf014e

Contents?: true

Size: 942 Bytes

Versions: 13

Compression:

Stored size: 942 Bytes

Contents

# frozen_string_literal: true

module Bullion
  module Models
    # ACMEv2 Order model
    class Order < ActiveRecord::Base
      serialize :identifiers, coder: JSON

      after_initialize :init_values, unless: :persisted?

      belongs_to :account
      has_many :authorizations

      validates :status, inclusion: { in: %w[invalid pending ready processing valid] }

      def init_values
        self.expires ||= Time.now + (60 * 60)
        self.not_before ||= Time.now
        self.not_after ||= Time.now + (60 * 60 * 24 * 90) # 90 days
      end

      def prep_authorizations!
        identifiers.each do |identifier|
          authorization = Authorization.new
          authorization.order = self
          authorization.identifier = identifier

          authorization.save

          authorization.prep_challenges!
        end
      end

      def certificate
        Certificate.find(certificate_id)
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
bullion-0.7.3 lib/bullion/models/order.rb
bullion-0.7.2 lib/bullion/models/order.rb
bullion-0.7.1 lib/bullion/models/order.rb
bullion-0.7.0 lib/bullion/models/order.rb
bullion-0.6.2 lib/bullion/models/order.rb
bullion-0.6.1 lib/bullion/models/order.rb
bullion-0.6.0 lib/bullion/models/order.rb
bullion-0.5.1 lib/bullion/models/order.rb
bullion-0.5.0 lib/bullion/models/order.rb
bullion-0.4.3 lib/bullion/models/order.rb
bullion-0.4.2 lib/bullion/models/order.rb
bullion-0.4.1 lib/bullion/models/order.rb
bullion-0.4.0 lib/bullion/models/order.rb