Module: ROM::Plugins::Schema::Timestamps

Defined in:
lib/rom/plugins/schema/timestamps.rb

Overview

A plugin for automatically adding timestamp fields to the schema definition

Examples:

schema do
  use :timestamps
end

# using non-default names
schema do
  use :timestamps, attributes: %i(created_on updated_on)
end

# using other types
schema do
  use :timestamps, type: Types::Date
end

Defined Under Namespace

Modules: DSL

Constant Summary collapse

DEFAULT_TIMESTAMPS =
%i[created_at updated_at].freeze
DEFAULT_TYPE =
ROM::Types::Time

Class Method Summary collapse

Class Method Details

.apply(schema, **options) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



30
31
32
33
34
35
36
37
38
39
# File 'lib/rom/plugins/schema/timestamps.rb', line 30

def self.apply(schema, **options)
  attributes = options.fetch(:attributes, DEFAULT_TIMESTAMPS)
  attrs_type = options.fetch(:type, DEFAULT_TYPE)

  attributes.each do |name|
    schema.attribute(name, attrs_type)
  end

  schema
end