Class: Clickwrap::Document

Inherits:
ApplicationRecord show all
Defined in:
lib/clickwrap/models/document.rb

Overview

A logical document — :terms, :privacy_notice — separate from the immutable versions that carry its actual bytes.

Instance Method Summary collapse

Instance Method Details

#current_version(locale: I18n.locale, at: Clickwrap.now) ⇒ Object

The version a policy should present right now for a locale: published, already effective, and not retired. A version scheduled for the future is deliberately not presentable yet — that is what effective_at is for. The version to present right now: published, already effective, and not retired. A version scheduled for the future is deliberately not presentable yet — that is what effective_at is for.

The ordering is by effective time, then by publication time as a tie-breaker for two versions scheduled for the same instant. Publishing always writes an effective_at, so no NULL reaches this comparison and PostgreSQL and SQLite agree about which document the server offered.



30
31
32
33
34
35
36
37
38
# File 'lib/clickwrap/models/document.rb', line 30

def current_version(locale: I18n.locale, at: Clickwrap.now)
  versions
    .published
    .effective_at_or_before(at)
    .not_retired_at(at)
    .for_locale(locale)
    .order(effective_at: :desc, published_at: :desc, created_at: :desc)
    .first
end

#to_sObject



44
# File 'lib/clickwrap/models/document.rb', line 44

def to_s = document_key

#version(label, locale: I18n.locale) ⇒ Object



40
41
42
# File 'lib/clickwrap/models/document.rb', line 40

def version(label, locale: I18n.locale)
  versions.for_locale(locale).find_by(version_label: label)
end