module Temporality

Temporality

Root module for temporal functionality, include it in ActiveRecord classes to benefit from the temporality features.

This functionality requires a starts_on and ends_on attribute pair defined on the models in which the module is included.

Example

This will define three classes with temporality constraints. An employment contract will be required to be temporally within the bounds of the legal entity with which it is made. A contract will also be required to have a temporally complete set of compensation records.

class LegalEntity < ActiveRecord::Base
  include Temporality
  has_many :employment_contracts
end

class EmploymentContract < ActiveRecord::Base
  include Temporality
  has_many :compensations
  belongs_to :legal_entity, temporality: {
    inclusion: true,
    auto_close: false,
    completeness: false,
    prevent_overlap: false
  }
end

class Compensation < ActiveRecord::Base
  include Temporality
  belongs_to :employment_contract, temporality: {
    inclusion: true,
    auto_close: true,
    completeness: true,
    prevent_overlap: true
  }
end

Constants

EXTENDS

Extensions to the included class

FUTURE_INFINITY

Used when no end date is defined

INCLUDES

Inclusions for the included class

PAST_INFINITY

Used when no start date is defined

PREPENDS

Prepended modules

VERSION

Temporality gem version

Public Class Methods

included(base) click to toggle source
# File lib/temporality.rb, line 76
def self.included(base)
  PREPENDS.each { |mod| base.prepend(mod) }
  EXTENDS.each  { |mod| base.extend(mod) }
  INCLUDES.each { |mod| base.include(mod) }

  # TODO : On va peut-ĂȘtre pas l'inclure 50 fois ce truc...
  ActiveRecord::Base.send(:include, DayCount)
end